Skip to content

Commit 7fedc48

Browse files
committed
Unify messages with stylelint-config-standard
1 parent ad966dc commit 7fedc48

File tree

5 files changed

+378
-126
lines changed

5 files changed

+378
-126
lines changed

__tests__/index.test.mjs

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,99 @@ describe('flags warnings with invalid scss', () => {
4242
assert.equal(result.errored, true);
4343
});
4444

45-
it('flags one warning', () => {
46-
assert.equal(result.results[0].warnings.length, 1);
45+
it('flags four warnings', () => {
46+
assert.equal(result.results[0].warnings.length, 4);
4747
});
4848

49-
it('correct warning text', () => {
50-
assert.equal(result.results[0].warnings[0].text, 'Expected variable to be kebab-case');
49+
it('correct warning text (function name)', () => {
50+
assert.equal(
51+
result.results[0].warnings[0].text,
52+
'Expected function name "FOO" to be kebab-case (scss/at-function-pattern)',
53+
);
5154
});
5255

53-
it('correct rule flagged', () => {
54-
assert.equal(result.results[0].warnings[0].rule, 'scss/dollar-variable-pattern');
56+
it('correct rule flagged (function name)', () => {
57+
assert.equal(result.results[0].warnings[0].rule, 'scss/at-function-pattern');
5558
});
5659

57-
it('correct severity flagged', () => {
60+
it('correct severity flagged (function name)', () => {
5861
assert.equal(result.results[0].warnings[0].severity, 'error');
5962
});
6063

61-
it('correct line number', () => {
62-
assert.equal(result.results[0].warnings[0].line, 1);
64+
it('correct line number (function name)', () => {
65+
assert.equal(result.results[0].warnings[0].line, 7);
6366
});
6467

65-
it('correct column number', () => {
66-
assert.equal(result.results[0].warnings[0].column, 1);
68+
it('correct column number (function name)', () => {
69+
assert.equal(result.results[0].warnings[0].column, 11);
70+
});
71+
72+
it('correct warning text (mixin name)', () => {
73+
assert.equal(
74+
result.results[0].warnings[1].text,
75+
'Expected mixin name "FOO" to be kebab-case (scss/at-mixin-pattern)',
76+
);
77+
});
78+
79+
it('correct rule flagged (mixin name)', () => {
80+
assert.equal(result.results[0].warnings[1].rule, 'scss/at-mixin-pattern');
81+
});
82+
83+
it('correct severity flagged (mixin name)', () => {
84+
assert.equal(result.results[0].warnings[1].severity, 'error');
85+
});
86+
87+
it('correct line number (mixin name)', () => {
88+
assert.equal(result.results[0].warnings[1].line, 11);
89+
});
90+
91+
it('correct column number (mixin name)', () => {
92+
assert.equal(result.results[0].warnings[1].column, 8);
93+
});
94+
95+
it('correct warning text (variable name)', () => {
96+
assert.equal(
97+
result.results[0].warnings[2].text,
98+
'Expected variable name "FOO" to be kebab-case (scss/dollar-variable-pattern)',
99+
);
100+
});
101+
102+
it('correct rule flagged (variable name)', () => {
103+
assert.equal(result.results[0].warnings[2].rule, 'scss/dollar-variable-pattern');
104+
});
105+
106+
it('correct severity flagged (variable name)', () => {
107+
assert.equal(result.results[0].warnings[2].severity, 'error');
108+
});
109+
110+
it('correct line number (variable name)', () => {
111+
assert.equal(result.results[0].warnings[2].line, 1);
112+
});
113+
114+
it('correct column number (variable name)', () => {
115+
assert.equal(result.results[0].warnings[2].column, 1);
116+
});
117+
118+
it('correct warning text (placeholder name)', () => {
119+
assert.equal(
120+
result.results[0].warnings[3].text,
121+
'Expected placeholder name "FOO" to be kebab-case (scss/percent-placeholder-pattern)',
122+
);
123+
});
124+
125+
it('correct rule flagged (placeholder name)', () => {
126+
assert.equal(result.results[0].warnings[3].rule, 'scss/percent-placeholder-pattern');
127+
});
128+
129+
it('correct severity flagged (placeholder name)', () => {
130+
assert.equal(result.results[0].warnings[3].severity, 'error');
131+
});
132+
133+
it('correct line number (placeholder name)', () => {
134+
assert.equal(result.results[0].warnings[3].line, 3);
135+
});
136+
137+
it('correct column number (placeholder name)', () => {
138+
assert.equal(result.results[0].warnings[3].column, 1);
67139
});
68140
});

__tests__/invalid.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
$FOO: 1;
2+
3+
%FOO {
4+
// Do nothing
5+
}
6+
7+
@function FOO() {
8+
// Do nothing
9+
}
10+
11+
@mixin FOO {
12+
// Do nothing
13+
}

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
'scss/at-function-pattern': [
2828
'^(-?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
2929
{
30-
message: 'Expected function name to be kebab-case',
30+
message: (name) => `Expected function name "${name}" to be kebab-case`,
3131
},
3232
],
3333
'scss/at-if-closing-brace-newline-after': 'always-last-in-chain',
@@ -37,7 +37,7 @@ module.exports = {
3737
'scss/at-mixin-pattern': [
3838
'^(-?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
3939
{
40-
message: 'Expected mixin name to be kebab-case',
40+
message: (name) => `Expected mixin name "${name}" to be kebab-case`,
4141
},
4242
],
4343
'scss/at-rule-conditional-no-parentheses': true,
@@ -53,7 +53,7 @@ module.exports = {
5353
'scss/dollar-variable-pattern': [
5454
'^(-?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
5555
{
56-
message: 'Expected variable to be kebab-case',
56+
message: (name) => `Expected variable name "${name}" to be kebab-case`,
5757
},
5858
],
5959
'scss/double-slash-comment-empty-line-before': [
@@ -67,7 +67,7 @@ module.exports = {
6767
'scss/percent-placeholder-pattern': [
6868
'^(-?[a-z][a-z0-9]*)(-[a-z0-9]+)*$',
6969
{
70-
message: 'Expected placeholder to be kebab-case',
70+
message: (name) => `Expected placeholder name "${name}" to be kebab-case`,
7171
},
7272
],
7373
},

0 commit comments

Comments
 (0)