Skip to content

Commit 249a55b

Browse files
committed
remove preceding whitespace
1 parent 2d84367 commit 249a55b

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,6 +4571,19 @@ Additionally, for `@param` and `@return` tags, the rule will flag unnecessary ty
45714571
The following patterns are considered problems:
45724572

45734573
````js
4574+
/** @type {string} */let a;
4575+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4576+
// Message: '@type' is redundant when using a type system.
4577+
4578+
/** @type {string} */ let a;
4579+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4580+
// Message: '@type' is redundant when using a type system.
4581+
4582+
/** @type {string} */
4583+
let a;
4584+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
4585+
// Message: '@type' is redundant when using a type system.
4586+
45744587
/** @type {string} */
45754588
let a;
45764589
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
@@ -4608,7 +4621,7 @@ let a;
46084621

46094622
/**
46104623
* Prior description.
4611-
*
4624+
*
46124625
* @template
46134626
*/
46144627
let a;

src/iterateJsdoc.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,23 @@ const getUtils = (
137137
const replacement = utils.stringify(jsdoc, specRewire);
138138

139139
if (!replacement) {
140-
return fixer.removeRange(jsdocNode.range);
140+
const text = sourceCode.getText();
141+
const lastLineBreakPos = text.slice(
142+
0, jsdocNode.range[0],
143+
).search(/\n[ \t]*$/u);
144+
if (lastLineBreakPos > -1) {
145+
return fixer.removeRange([
146+
lastLineBreakPos, jsdocNode.range[1],
147+
]);
148+
}
149+
150+
return fixer.removeRange(
151+
(/\s/u).test(text.charAt(jsdocNode.range[1])) ?
152+
[
153+
jsdocNode.range[0], jsdocNode.range[1] + 1,
154+
] :
155+
jsdocNode.range,
156+
);
141157
}
142158

143159
return fixer.replaceText(jsdocNode, replacement);

test/rules/assertions/checkTagNames.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,58 @@ const ONE_CLOSURE_TAGS_COMMENT = buildTagBlock({
2424

2525
export default {
2626
invalid: [
27+
{
28+
code: `/** @type {string} */let a;
29+
`,
30+
errors: [
31+
{
32+
line: 1,
33+
message: '\'@type\' is redundant when using a type system.',
34+
},
35+
],
36+
options: [
37+
{
38+
typed: true,
39+
},
40+
],
41+
output: `let a;
42+
`,
43+
},
44+
{
45+
code: `/** @type {string} */ let a;
46+
`,
47+
errors: [
48+
{
49+
line: 1,
50+
message: '\'@type\' is redundant when using a type system.',
51+
},
52+
],
53+
options: [
54+
{
55+
typed: true,
56+
},
57+
],
58+
output: `let a;
59+
`,
60+
},
61+
{
62+
code: `/** @type {string} */
63+
let a;
64+
`,
65+
errors: [
66+
{
67+
line: 1,
68+
message: '\'@type\' is redundant when using a type system.',
69+
},
70+
],
71+
options: [
72+
{
73+
typed: true,
74+
},
75+
],
76+
output: ` let a;
77+
`,
78+
},
2779
{
2880
code: `
2981
/** @type {string} */
@@ -41,7 +93,6 @@ export default {
4193
},
4294
],
4395
output: `
44-
4596
let a;
4697
`,
4798
},
@@ -109,7 +160,6 @@ export default {
109160
},
110161
],
111162
output: `
112-
113163
let a;
114164
`,
115165
},
@@ -133,7 +183,6 @@ export default {
133183
],
134184
output: `
135185
const a = {
136-
137186
b: true,
138187
};
139188
`,
@@ -155,15 +204,14 @@ export default {
155204
},
156205
],
157206
output: `
158-
159207
let a;
160208
`,
161209
},
162210
{
163211
code: `
164212
/**
165213
* Prior description.
166-
*
214+
*
167215
* @template
168216
*/
169217
let a;
@@ -182,7 +230,7 @@ export default {
182230
output: `
183231
/**
184232
* Prior description.
185-
*
233+
*
186234
*/
187235
let a;
188236
`,
@@ -204,7 +252,6 @@ export default {
204252
},
205253
],
206254
output: `
207-
208255
function takesOne(param) {}
209256
`,
210257
},
@@ -225,7 +272,6 @@ export default {
225272
},
226273
],
227274
output: `
228-
229275
function takesOne(param) {}
230276
`,
231277
},

0 commit comments

Comments
 (0)