@virmator/lint 14.35.0 → 14.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,12 @@ function getParameterText({ node, sourceCode, }) {
|
|
|
15
15
|
return '()';
|
|
16
16
|
}
|
|
17
17
|
const openParen = sourceCode.getTokenBefore(firstParam);
|
|
18
|
-
|
|
18
|
+
/** The parameter list may end with a trailing comma, which sits between the last param and `)`. */
|
|
19
|
+
const closeParen = sourceCode.getTokenAfter(lastParam, {
|
|
20
|
+
filter(token) {
|
|
21
|
+
return token.value !== ',';
|
|
22
|
+
},
|
|
23
|
+
});
|
|
19
24
|
if (openParen?.value === '(' && closeParen?.value === ')') {
|
|
20
25
|
return sourceCode.text.slice(openParen.range[0], closeParen.range[1]);
|
|
21
26
|
}
|
|
@@ -10,12 +10,14 @@ function parseWordsComment(comment) {
|
|
|
10
10
|
if (!range || !directiveMatch) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const unnormalizedWords = (directiveMatch[1] ?? '')
|
|
14
14
|
.trim()
|
|
15
15
|
.split(/[\s,]+/)
|
|
16
16
|
.filter((word) => word !== '');
|
|
17
|
+
const words = unnormalizedWords.map((word) => word.toLowerCase());
|
|
17
18
|
return {
|
|
18
19
|
comment,
|
|
20
|
+
hasNonLowercaseWords: unnormalizedWords.some((word) => word !== word.toLowerCase()),
|
|
19
21
|
range,
|
|
20
22
|
words,
|
|
21
23
|
};
|
|
@@ -53,6 +55,7 @@ const rule = {
|
|
|
53
55
|
description: 'Require all cspell word allow-list comments in a file to be combined.',
|
|
54
56
|
},
|
|
55
57
|
messages: {
|
|
58
|
+
lowercaseWords: 'Lowercase all words in `cspell:words` comments.',
|
|
56
59
|
singleWordsComment: 'Combine all `cspell:words` comments in a file into a single comment.',
|
|
57
60
|
},
|
|
58
61
|
schema: [],
|
|
@@ -66,7 +69,8 @@ const rule = {
|
|
|
66
69
|
.map((comment) => parseWordsComment(comment))
|
|
67
70
|
.filter((wordsComment) => wordsComment != undefined);
|
|
68
71
|
const [firstWordsComment, ...extraWordsComments] = wordsComments;
|
|
69
|
-
if (!firstWordsComment ||
|
|
72
|
+
if (!firstWordsComment ||
|
|
73
|
+
(!extraWordsComments.length && !firstWordsComment.hasNonLowercaseWords)) {
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
76
|
const combinedWords = wordsComments.flatMap((wordsComment) => {
|
|
@@ -75,6 +79,21 @@ const rule = {
|
|
|
75
79
|
const uniqueWords = combinedWords.filter((word, wordIndex) => {
|
|
76
80
|
return combinedWords.indexOf(word) === wordIndex;
|
|
77
81
|
});
|
|
82
|
+
if (!extraWordsComments.length) {
|
|
83
|
+
context.report({
|
|
84
|
+
loc: firstWordsComment.comment.loc ?? {
|
|
85
|
+
start: sourceCode.getLocFromIndex(firstWordsComment.range[0]),
|
|
86
|
+
end: sourceCode.getLocFromIndex(firstWordsComment.range[1]),
|
|
87
|
+
},
|
|
88
|
+
messageId: 'lowercaseWords',
|
|
89
|
+
fix(fixer) {
|
|
90
|
+
return fixer.replaceTextRange(firstWordsComment.range, createCombinedCommentText({
|
|
91
|
+
comment: firstWordsComment.comment,
|
|
92
|
+
words: uniqueWords,
|
|
93
|
+
}));
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
78
97
|
extraWordsComments.forEach((extraWordsComment, extraIndex) => {
|
|
79
98
|
context.report({
|
|
80
99
|
loc: extraWordsComment.comment.loc ?? {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virmator/lint",
|
|
3
|
-
"version": "14.35.
|
|
3
|
+
"version": "14.35.2",
|
|
4
4
|
"description": "Default ESLint linting plugin for virmator.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"virmator",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@augment-vir/assert": "^32.2.4",
|
|
36
36
|
"@augment-vir/common": "^32.2.4",
|
|
37
37
|
"@augment-vir/node": "^32.2.4",
|
|
38
|
-
"@virmator/core": "^14.35.
|
|
38
|
+
"@virmator/core": "^14.35.2",
|
|
39
39
|
"globals": "^17.11.0",
|
|
40
40
|
"jiti": "^2.7.0",
|
|
41
41
|
"mri": "^1.2.0"
|
|
@@ -56,7 +56,12 @@ function getParameterText({
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const openParen = sourceCode.getTokenBefore(firstParam);
|
|
59
|
-
|
|
59
|
+
/** The parameter list may end with a trailing comma, which sits between the last param and `)`. */
|
|
60
|
+
const closeParen = sourceCode.getTokenAfter(lastParam, {
|
|
61
|
+
filter(token) {
|
|
62
|
+
return token.value !== ',';
|
|
63
|
+
},
|
|
64
|
+
});
|
|
60
65
|
|
|
61
66
|
if (openParen?.value === '(' && closeParen?.value === ')') {
|
|
62
67
|
return sourceCode.text.slice(openParen.range[0], closeParen.range[1]);
|
|
@@ -10,6 +10,7 @@ const wordsDirectiveRegExp = /\bcspell:words?\b[\t :]*(.*)/i;
|
|
|
10
10
|
|
|
11
11
|
type WordsComment = {
|
|
12
12
|
comment: Comment;
|
|
13
|
+
hasNonLowercaseWords: boolean;
|
|
13
14
|
range: [
|
|
14
15
|
number,
|
|
15
16
|
number,
|
|
@@ -25,13 +26,15 @@ function parseWordsComment(comment: Comment): WordsComment | undefined {
|
|
|
25
26
|
return undefined;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
+
const unnormalizedWords = (directiveMatch[1] ?? '')
|
|
29
30
|
.trim()
|
|
30
31
|
.split(/[\s,]+/)
|
|
31
32
|
.filter((word) => word !== '');
|
|
33
|
+
const words = unnormalizedWords.map((word) => word.toLowerCase());
|
|
32
34
|
|
|
33
35
|
return {
|
|
34
36
|
comment,
|
|
37
|
+
hasNonLowercaseWords: unnormalizedWords.some((word) => word !== word.toLowerCase()),
|
|
35
38
|
range,
|
|
36
39
|
words,
|
|
37
40
|
};
|
|
@@ -93,6 +96,7 @@ const rule: Rule.RuleModule = {
|
|
|
93
96
|
description: 'Require all cspell word allow-list comments in a file to be combined.',
|
|
94
97
|
},
|
|
95
98
|
messages: {
|
|
99
|
+
lowercaseWords: 'Lowercase all words in `cspell:words` comments.',
|
|
96
100
|
singleWordsComment:
|
|
97
101
|
'Combine all `cspell:words` comments in a file into a single comment.',
|
|
98
102
|
},
|
|
@@ -112,7 +116,10 @@ const rule: Rule.RuleModule = {
|
|
|
112
116
|
...extraWordsComments
|
|
113
117
|
] = wordsComments;
|
|
114
118
|
|
|
115
|
-
if (
|
|
119
|
+
if (
|
|
120
|
+
!firstWordsComment ||
|
|
121
|
+
(!extraWordsComments.length && !firstWordsComment.hasNonLowercaseWords)
|
|
122
|
+
) {
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
125
|
|
|
@@ -123,6 +130,25 @@ const rule: Rule.RuleModule = {
|
|
|
123
130
|
return combinedWords.indexOf(word) === wordIndex;
|
|
124
131
|
});
|
|
125
132
|
|
|
133
|
+
if (!extraWordsComments.length) {
|
|
134
|
+
context.report({
|
|
135
|
+
loc: firstWordsComment.comment.loc ?? {
|
|
136
|
+
start: sourceCode.getLocFromIndex(firstWordsComment.range[0]),
|
|
137
|
+
end: sourceCode.getLocFromIndex(firstWordsComment.range[1]),
|
|
138
|
+
},
|
|
139
|
+
messageId: 'lowercaseWords',
|
|
140
|
+
fix(fixer) {
|
|
141
|
+
return fixer.replaceTextRange(
|
|
142
|
+
firstWordsComment.range,
|
|
143
|
+
createCombinedCommentText({
|
|
144
|
+
comment: firstWordsComment.comment,
|
|
145
|
+
words: uniqueWords,
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
126
152
|
extraWordsComments.forEach((extraWordsComment, extraIndex) => {
|
|
127
153
|
context.report({
|
|
128
154
|
loc: extraWordsComment.comment.loc ?? {
|