ignore-lint-errors 1.1.5 → 1.2.1
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.
- package/README.md +15 -9
- package/dist/src/steps/ignore-errors/eslint.js +9 -2
- package/dist/src/steps/ignore-errors/typescript.js +11 -5
- package/dist/src/utils/ignore-errors/eslint.js +37 -13
- package/dist/src/utils/ignore-errors/oxlint.js +6 -15
- package/dist/src/utils/ignore-errors/shared/are-template-tags-valid.js +15 -0
- package/dist/src/utils/ignore-errors/shared/find-template-tags.js +21 -0
- package/dist/src/utils/ignore-errors/shared/get-ignored-rules-in-template.js +29 -0
- package/dist/src/utils/ignore-errors/shared/get-ignored-rules.js +31 -0
- package/dist/src/utils/ignore-errors/shared/ignore-error.js +39 -0
- package/dist/src/utils/ignore-errors/shared/index.js +6 -65
- package/dist/src/utils/ignore-errors/shared/is-template-tag.js +3 -0
- package/dist/src/utils/ignore-errors/stylelint.js +6 -15
- package/dist/src/utils/ignore-errors/typescript.js +61 -44
- package/dist/src/utils/linters/shared/get-files-with-errors.js +29 -0
- package/dist/src/utils/linters/shared/get-message.js +3 -0
- package/dist/src/utils/linters/shared/get-relative-path.js +4 -0
- package/dist/src/utils/linters/shared/index.js +3 -36
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -74,33 +74,39 @@ pnpx ignore-lint-errors --root <path/to/your/project>
|
|
|
74
74
|
|
|
75
75
|
Pass `--src` to lint specific files.
|
|
76
76
|
|
|
77
|
+
eslint:
|
|
78
|
+
|
|
77
79
|
```sh
|
|
78
|
-
#
|
|
80
|
+
# Specific files
|
|
79
81
|
pnpx ignore-lint-errors --linter eslint --src app/components/example-1.gts app/templates/example-2.gts
|
|
80
82
|
|
|
81
|
-
#
|
|
83
|
+
# Specific directories
|
|
82
84
|
pnpx ignore-lint-errors --linter eslint --src app tests
|
|
83
85
|
|
|
84
|
-
#
|
|
86
|
+
# Globs
|
|
85
87
|
pnpx ignore-lint-errors --linter eslint --src app/{components,templates}/**/*.gts
|
|
86
88
|
```
|
|
87
89
|
|
|
90
|
+
oxlint:
|
|
91
|
+
|
|
88
92
|
```sh
|
|
89
|
-
#
|
|
93
|
+
# Specific files
|
|
90
94
|
pnpx ignore-lint-errors --linter oxlint --src app/components/example-1.gts app/templates/example-2.gts
|
|
91
95
|
|
|
92
|
-
#
|
|
96
|
+
# Specific directories
|
|
93
97
|
pnpx ignore-lint-errors --linter oxlint --src app tests
|
|
94
98
|
|
|
95
|
-
#
|
|
99
|
+
# Globs
|
|
96
100
|
pnpx ignore-lint-errors --linter oxlint --src app/{components,templates}/**/*.gts
|
|
97
101
|
```
|
|
98
102
|
|
|
103
|
+
stylelint:
|
|
104
|
+
|
|
99
105
|
```sh
|
|
100
|
-
#
|
|
106
|
+
# Specific files
|
|
101
107
|
pnpx ignore-lint-errors --linter stylelint --src app/components/example-1.module.css app/templates/example-2.module.css
|
|
102
108
|
|
|
103
|
-
#
|
|
109
|
+
# Globs
|
|
104
110
|
pnpx ignore-lint-errors --linter stylelint --src app/components/**/*.css
|
|
105
111
|
```
|
|
106
112
|
|
|
@@ -127,7 +133,7 @@ pnpm build
|
|
|
127
133
|
## Compatibility
|
|
128
134
|
|
|
129
135
|
- Node.js v22 or above
|
|
130
|
-
- Tested against `eslint@
|
|
136
|
+
- Tested against `eslint@v10`, `glint@v2`, `oxlint@v1`, `stylelint@v17`, `typescript@v6`
|
|
131
137
|
|
|
132
138
|
|
|
133
139
|
## Contributing
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { removeFiles } from '@codemod-utils/files';
|
|
4
|
-
import { ignoreErrors } from '../../utils/ignore-errors/eslint.js';
|
|
4
|
+
import { ignoreErrors, ignoreErrorsTemplateTag, } from '../../utils/ignore-errors/eslint.js';
|
|
5
|
+
import { isTemplateTag } from '../../utils/ignore-errors/shared/index.js';
|
|
5
6
|
import { outputFilePath, parseOutputFile } from '../../utils/linters/eslint.js';
|
|
6
7
|
export function ignoreErrorsFromEslint(options) {
|
|
7
8
|
const { dependencies, projectRoot } = options;
|
|
@@ -12,7 +13,13 @@ export function ignoreErrorsFromEslint(options) {
|
|
|
12
13
|
const filesWithErrors = parseOutputFile(outputFile, projectRoot);
|
|
13
14
|
filesWithErrors.forEach(({ filePath, lintErrors }) => {
|
|
14
15
|
const file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
15
|
-
|
|
16
|
+
let newFile;
|
|
17
|
+
if (isTemplateTag(filePath)) {
|
|
18
|
+
newFile = ignoreErrorsTemplateTag(file, lintErrors);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
newFile = ignoreErrors(file, lintErrors);
|
|
22
|
+
}
|
|
16
23
|
writeFileSync(join(projectRoot, filePath), newFile, 'utf8');
|
|
17
24
|
});
|
|
18
25
|
removeFiles([outputFilePath], { projectRoot });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { removeFiles } from '@codemod-utils/files';
|
|
4
|
-
import { areTemplateTagsValid } from '../../utils/ignore-errors/shared/index.js';
|
|
5
|
-
import { ignoreErrors, ignoreErrorsFallback, } from '../../utils/ignore-errors/typescript.js';
|
|
4
|
+
import { areTemplateTagsValid, isTemplateTag, } from '../../utils/ignore-errors/shared/index.js';
|
|
5
|
+
import { ignoreErrors, ignoreErrorsFallback, ignoreErrorsTemplateTag, } from '../../utils/ignore-errors/typescript.js';
|
|
6
6
|
import { outputFilePath, parseOutputFile, } from '../../utils/linters/typescript.js';
|
|
7
7
|
export function ignoreErrorsFromTypescript(options) {
|
|
8
8
|
const { dependencies, projectRoot } = options;
|
|
@@ -13,9 +13,15 @@ export function ignoreErrorsFromTypescript(options) {
|
|
|
13
13
|
const filesWithErrors = parseOutputFile(outputFile);
|
|
14
14
|
filesWithErrors.forEach(({ filePath, lintErrors }) => {
|
|
15
15
|
const file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
16
|
-
let newFile
|
|
17
|
-
if (
|
|
18
|
-
newFile =
|
|
16
|
+
let newFile;
|
|
17
|
+
if (isTemplateTag(filePath)) {
|
|
18
|
+
newFile = ignoreErrorsTemplateTag(file, lintErrors);
|
|
19
|
+
if (!areTemplateTagsValid(newFile)) {
|
|
20
|
+
newFile = ignoreErrorsFallback(file, lintErrors);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
newFile = ignoreErrors(file, lintErrors);
|
|
19
25
|
}
|
|
20
26
|
writeFileSync(join(projectRoot, filePath), newFile, 'utf8');
|
|
21
27
|
});
|
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
import { EOL } from 'node:os';
|
|
2
|
-
import {
|
|
2
|
+
import { findTemplateTags, ignoreError } from './shared/index.js';
|
|
3
|
+
const ignoreDirective = 'eslint-disable-next-line';
|
|
3
4
|
export function ignoreErrors(file, lintErrors) {
|
|
4
5
|
const lines = file.split(EOL);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
9
|
-
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
6
|
+
lintErrors.forEach((lintError) => {
|
|
7
|
+
ignoreError(lintError, {
|
|
8
|
+
commentStyle: 'javascript-inline',
|
|
10
9
|
ignoreDirective,
|
|
10
|
+
lines,
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
});
|
|
13
|
+
return lines.join(EOL);
|
|
14
|
+
}
|
|
15
|
+
export function ignoreErrorsTemplateTag(file, lintErrors) {
|
|
16
|
+
const lines = file.split(EOL);
|
|
17
|
+
const templateTags = findTemplateTags(file);
|
|
18
|
+
lintErrors.forEach((lintError) => {
|
|
19
|
+
const { line, message } = lintError;
|
|
20
|
+
const templateTagIndex = templateTags.findIndex(({ lineRange }) => {
|
|
21
|
+
return lineRange.start <= line && line <= lineRange.end;
|
|
22
|
+
});
|
|
23
|
+
const erroredInTemplate = templateTagIndex >= 0;
|
|
24
|
+
if (!erroredInTemplate) {
|
|
25
|
+
ignoreError(lintError, {
|
|
26
|
+
commentStyle: 'javascript-inline',
|
|
27
|
+
ignoreDirective,
|
|
28
|
+
lines,
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
14
31
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
const { contents, lineRange } = templateTags[templateTagIndex];
|
|
33
|
+
if (lineRange.start < lineRange.end) {
|
|
34
|
+
ignoreError(lintError, {
|
|
35
|
+
commentStyle: 'template-inline',
|
|
36
|
+
ignoreDirective,
|
|
37
|
+
lines,
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
20
40
|
}
|
|
41
|
+
const currentIndex = line - 1;
|
|
42
|
+
const comment = `{{! ${ignoreDirective} ${message} }}`;
|
|
43
|
+
const newTemplate = lines[currentIndex].replace(/<template>(.+)<\/template>/, [`<template>${comment}`, `${contents}</template>`].join(EOL));
|
|
44
|
+
lines.splice(currentIndex, 1, newTemplate);
|
|
21
45
|
});
|
|
22
46
|
return lines.join(EOL);
|
|
23
47
|
}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { EOL } from 'node:os';
|
|
2
|
-
import {
|
|
2
|
+
import { ignoreError } from './shared/index.js';
|
|
3
|
+
const ignoreDirective = 'oxlint-disable-next-line';
|
|
3
4
|
export function ignoreErrors(file, lintErrors) {
|
|
4
5
|
const lines = file.split(EOL);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
9
|
-
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
6
|
+
lintErrors.forEach((lintError) => {
|
|
7
|
+
ignoreError(lintError, {
|
|
8
|
+
commentStyle: 'javascript-inline',
|
|
10
9
|
ignoreDirective,
|
|
10
|
+
lines,
|
|
11
11
|
});
|
|
12
|
-
if (ignoredRules.length === 0) {
|
|
13
|
-
lines.splice(currentIndex, 0, `// ${ignoreDirective} ${message}`);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const newMessage = [...ignoredRules, ...message.split(', ')]
|
|
17
|
-
.sort()
|
|
18
|
-
.join(', ');
|
|
19
|
-
lines.splice(previousIndex, 1, `// ${ignoreDirective} ${newMessage}`);
|
|
20
|
-
}
|
|
21
12
|
});
|
|
22
13
|
return lines.join(EOL);
|
|
23
14
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AST } from '@codemod-utils/ast-template';
|
|
2
|
+
import { findTemplateTags } from '@codemod-utils/ast-template-tag';
|
|
3
|
+
export function areTemplateTagsValid(file) {
|
|
4
|
+
let isValid = true;
|
|
5
|
+
try {
|
|
6
|
+
const templateTags = findTemplateTags(file);
|
|
7
|
+
templateTags.forEach(({ contents }) => {
|
|
8
|
+
AST.traverse(contents);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
isValid = false;
|
|
13
|
+
}
|
|
14
|
+
return isValid;
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { findTemplateTags as upstreamFindTemplateTags } from '@codemod-utils/ast-template-tag';
|
|
2
|
+
export function findTemplateTags(file) {
|
|
3
|
+
function getLOC(file) {
|
|
4
|
+
const matches = file.match(/\r?\n/g);
|
|
5
|
+
return (matches ?? []).length;
|
|
6
|
+
}
|
|
7
|
+
const templateTags = upstreamFindTemplateTags(file);
|
|
8
|
+
return templateTags.map((templateTag) => {
|
|
9
|
+
const { contents, range } = templateTag;
|
|
10
|
+
const lineStart = getLOC(file.substring(0, range.startChar)) + 1;
|
|
11
|
+
const lineEnd = getLOC(file.substring(0, range.endChar)) + 1;
|
|
12
|
+
const lineRange = {
|
|
13
|
+
end: lineEnd,
|
|
14
|
+
start: lineStart,
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
contents,
|
|
18
|
+
lineRange,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AST } from '@codemod-utils/ast-template';
|
|
2
|
+
export function getIgnoredRulesInTemplate(lineOfCode, data) {
|
|
3
|
+
const { ignoreDirective } = data;
|
|
4
|
+
let ignoredRules = [];
|
|
5
|
+
try {
|
|
6
|
+
AST.traverse(lineOfCode, {
|
|
7
|
+
MustacheCommentStatement(node) {
|
|
8
|
+
const comment = node.value.trim();
|
|
9
|
+
if (!comment.startsWith(ignoreDirective)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
ignoredRules = comment
|
|
13
|
+
.replace(new RegExp(`^${ignoreDirective}\\s*`, 'g'), '')
|
|
14
|
+
.split(',')
|
|
15
|
+
.reduce((accumulator, token) => {
|
|
16
|
+
const rule = token.trim();
|
|
17
|
+
if (rule) {
|
|
18
|
+
accumulator.push(rule);
|
|
19
|
+
}
|
|
20
|
+
return accumulator;
|
|
21
|
+
}, []);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Do nothing
|
|
27
|
+
}
|
|
28
|
+
return ignoredRules;
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AST } from '@codemod-utils/ast-javascript';
|
|
2
|
+
export function getIgnoredRules(lineOfCode, data) {
|
|
3
|
+
const { ignoreDirective } = data;
|
|
4
|
+
let ignoredRules = [];
|
|
5
|
+
try {
|
|
6
|
+
AST.traverse(lineOfCode, {
|
|
7
|
+
visitComment(path) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
9
|
+
const comment = path.value.value.trim();
|
|
10
|
+
if (!comment.startsWith(ignoreDirective)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
ignoredRules = comment
|
|
14
|
+
.replace(new RegExp(`^${ignoreDirective}\\s*`, 'g'), '')
|
|
15
|
+
.split(',')
|
|
16
|
+
.reduce((accumulator, token) => {
|
|
17
|
+
const rule = token.trim();
|
|
18
|
+
if (rule) {
|
|
19
|
+
accumulator.push(rule);
|
|
20
|
+
}
|
|
21
|
+
return accumulator;
|
|
22
|
+
}, []);
|
|
23
|
+
return false;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Do nothing
|
|
29
|
+
}
|
|
30
|
+
return ignoredRules;
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getIgnoredRules } from './get-ignored-rules.js';
|
|
2
|
+
import { getIgnoredRulesInTemplate } from './get-ignored-rules-in-template.js';
|
|
3
|
+
function append(ignoredRules, message) {
|
|
4
|
+
return [...ignoredRules, ...message.split(', ')].sort().join(', ');
|
|
5
|
+
}
|
|
6
|
+
function getComment(message, data) {
|
|
7
|
+
const { commentStyle, ignoreDirective } = data;
|
|
8
|
+
switch (commentStyle) {
|
|
9
|
+
case 'javascript-block': {
|
|
10
|
+
return `/* ${ignoreDirective} ${message} */`;
|
|
11
|
+
}
|
|
12
|
+
case 'javascript-inline': {
|
|
13
|
+
return `// ${ignoreDirective} ${message}`;
|
|
14
|
+
}
|
|
15
|
+
case 'template-inline': {
|
|
16
|
+
return `{{! ${ignoreDirective} ${message} }}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function ignoreError(lintError, data) {
|
|
21
|
+
// eslint-disable-next-line prefer-const
|
|
22
|
+
let { line, message } = lintError;
|
|
23
|
+
const { commentStyle, ignoreDirective, lines } = data;
|
|
24
|
+
const currentIndex = line - 1;
|
|
25
|
+
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
26
|
+
const ignoredRules = commentStyle === 'template-inline'
|
|
27
|
+
? getIgnoredRulesInTemplate(lines[previousIndex], { ignoreDirective })
|
|
28
|
+
: getIgnoredRules(lines[previousIndex], { ignoreDirective });
|
|
29
|
+
if (ignoredRules.length > 0) {
|
|
30
|
+
message = append(ignoredRules, message);
|
|
31
|
+
}
|
|
32
|
+
const comment = getComment(message, data);
|
|
33
|
+
if (ignoredRules.length === 0) {
|
|
34
|
+
lines.splice(currentIndex, 0, comment);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
lines.splice(previousIndex, 1, comment);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,65 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const templateTags = upstreamFindTemplateTags(file);
|
|
8
|
-
templateTags.forEach(({ contents }) => {
|
|
9
|
-
ASTTemplate.traverse(contents);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
isValid = false;
|
|
14
|
-
}
|
|
15
|
-
return isValid;
|
|
16
|
-
}
|
|
17
|
-
export function findTemplateTags(file) {
|
|
18
|
-
function getLOC(file) {
|
|
19
|
-
const matches = file.match(/\r?\n/g);
|
|
20
|
-
return (matches ?? []).length;
|
|
21
|
-
}
|
|
22
|
-
const templateTags = upstreamFindTemplateTags(file);
|
|
23
|
-
return templateTags.map((templateTag) => {
|
|
24
|
-
const { contents, range } = templateTag;
|
|
25
|
-
const lineStart = getLOC(file.substring(0, range.startChar)) + 1;
|
|
26
|
-
const lineEnd = getLOC(file.substring(0, range.endChar)) + 1;
|
|
27
|
-
const lineRange = {
|
|
28
|
-
end: lineEnd,
|
|
29
|
-
start: lineStart,
|
|
30
|
-
};
|
|
31
|
-
return {
|
|
32
|
-
contents,
|
|
33
|
-
lineRange,
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export function getIgnoredRules(lineOfCode, options) {
|
|
38
|
-
let ignoredRules = [];
|
|
39
|
-
try {
|
|
40
|
-
ASTJavaScript.traverse(lineOfCode, {
|
|
41
|
-
visitComment(path) {
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
43
|
-
const comment = path.value.value.trim();
|
|
44
|
-
if (!comment.startsWith(options.ignoreDirective)) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
ignoredRules = comment
|
|
48
|
-
.replace(new RegExp(`^${options.ignoreDirective}\\s*`, 'g'), '')
|
|
49
|
-
.split(',')
|
|
50
|
-
.reduce((accumulator, token) => {
|
|
51
|
-
const rule = token.trim();
|
|
52
|
-
if (rule) {
|
|
53
|
-
accumulator.push(rule);
|
|
54
|
-
}
|
|
55
|
-
return accumulator;
|
|
56
|
-
}, []);
|
|
57
|
-
return false;
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
// Do nothing
|
|
63
|
-
}
|
|
64
|
-
return ignoredRules;
|
|
65
|
-
}
|
|
1
|
+
export * from './are-template-tags-valid.js';
|
|
2
|
+
export * from './find-template-tags.js';
|
|
3
|
+
export * from './get-ignored-rules.js';
|
|
4
|
+
export * from './get-ignored-rules-in-template.js';
|
|
5
|
+
export * from './ignore-error.js';
|
|
6
|
+
export * from './is-template-tag.js';
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { EOL } from 'node:os';
|
|
2
|
-
import {
|
|
2
|
+
import { ignoreError } from './shared/index.js';
|
|
3
|
+
const ignoreDirective = 'stylelint-disable-next-line';
|
|
3
4
|
export function ignoreErrors(file, lintErrors) {
|
|
4
5
|
const lines = file.split(EOL);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
9
|
-
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
6
|
+
lintErrors.forEach((lintError) => {
|
|
7
|
+
ignoreError(lintError, {
|
|
8
|
+
commentStyle: 'javascript-block',
|
|
10
9
|
ignoreDirective,
|
|
10
|
+
lines,
|
|
11
11
|
});
|
|
12
|
-
if (ignoredRules.length === 0) {
|
|
13
|
-
lines.splice(currentIndex, 0, `/* ${ignoreDirective} ${message} */`);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const newMessage = [...ignoredRules, ...message.split(', ')]
|
|
17
|
-
.sort()
|
|
18
|
-
.join(', ');
|
|
19
|
-
lines.splice(previousIndex, 1, `/* ${ignoreDirective} ${newMessage} */`);
|
|
20
|
-
}
|
|
21
12
|
});
|
|
22
13
|
return lines.join(EOL);
|
|
23
14
|
}
|
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
import { EOL } from 'node:os';
|
|
2
2
|
import { updateTemplates } from '@codemod-utils/ast-template-tag';
|
|
3
3
|
import { findTemplateTags, getIgnoredRules } from './shared/index.js';
|
|
4
|
+
function getComment(message, data) {
|
|
5
|
+
const { ignoreDirective } = data;
|
|
6
|
+
return `// ${ignoreDirective}: ${message}`;
|
|
7
|
+
}
|
|
8
|
+
function ignoreError(lintError, data) {
|
|
9
|
+
const { line, message } = lintError;
|
|
10
|
+
const { lines } = data;
|
|
11
|
+
const currentIndex = line - 1;
|
|
12
|
+
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
13
|
+
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
14
|
+
ignoreDirective: 'eslint-disable-next-line',
|
|
15
|
+
});
|
|
16
|
+
const comment = getComment(message, data);
|
|
17
|
+
if (ignoredRules.length === 0) {
|
|
18
|
+
lines.splice(currentIndex, 0, comment);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
lines.splice(previousIndex, 0, comment);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const ignoreDirective = '@ts-expect-error';
|
|
4
25
|
export function ignoreErrors(file, lintErrors) {
|
|
5
26
|
const lines = file.split(EOL);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const templateTagIndex = templateTags.findIndex(({ lineRange }) => {
|
|
11
|
-
return lineRange.start <= line && line <= lineRange.end;
|
|
27
|
+
lintErrors.forEach((lintError) => {
|
|
28
|
+
ignoreError(lintError, {
|
|
29
|
+
ignoreDirective,
|
|
30
|
+
lines,
|
|
12
31
|
});
|
|
13
|
-
const erroredInTemplate = templateTagIndex >= 0;
|
|
14
|
-
if (erroredInTemplate) {
|
|
15
|
-
const comment = `{{! @glint-expect-error: ${message} }}`;
|
|
16
|
-
const { contents, lineRange } = templateTags[templateTagIndex];
|
|
17
|
-
if (lineRange.start === lineRange.end) {
|
|
18
|
-
const newTemplate = lines[currentIndex].replace(/<template>(.+)<\/template>/, [`<template>${comment}`, `${contents}</template>`].join(EOL));
|
|
19
|
-
lines.splice(currentIndex, 1, newTemplate);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
lines.splice(currentIndex, 0, comment);
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const comment = `// @ts-expect-error: ${message}`;
|
|
27
|
-
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
28
|
-
ignoreDirective: 'eslint-disable-next-line',
|
|
29
|
-
});
|
|
30
|
-
if (ignoredRules.length === 0) {
|
|
31
|
-
lines.splice(currentIndex, 0, comment);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
lines.splice(previousIndex, 0, comment);
|
|
35
|
-
}
|
|
36
32
|
});
|
|
37
33
|
return lines.join(EOL);
|
|
38
34
|
}
|
|
@@ -41,26 +37,19 @@ export function ignoreErrorsFallback(file, lintErrors) {
|
|
|
41
37
|
const lines = file.split(EOL);
|
|
42
38
|
const templateTags = findTemplateTags(file);
|
|
43
39
|
let hasErrorInTemplate = false;
|
|
44
|
-
lintErrors.forEach((
|
|
45
|
-
const
|
|
46
|
-
const previousIndex = Math.max(currentIndex - 1, 0);
|
|
40
|
+
lintErrors.forEach((lintError) => {
|
|
41
|
+
const { line } = lintError;
|
|
47
42
|
const erroredInTemplate = templateTags.some(({ lineRange }) => {
|
|
48
43
|
return lineRange.start <= line && line <= lineRange.end;
|
|
49
44
|
});
|
|
50
|
-
if (erroredInTemplate) {
|
|
51
|
-
|
|
45
|
+
if (!erroredInTemplate) {
|
|
46
|
+
ignoreError(lintError, {
|
|
47
|
+
ignoreDirective,
|
|
48
|
+
lines,
|
|
49
|
+
});
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
const ignoredRules = getIgnoredRules(lines[previousIndex], {
|
|
56
|
-
ignoreDirective: 'eslint-disable-next-line',
|
|
57
|
-
});
|
|
58
|
-
if (ignoredRules.length === 0) {
|
|
59
|
-
lines.splice(currentIndex, 0, comment);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
lines.splice(previousIndex, 0, comment);
|
|
63
|
-
}
|
|
52
|
+
hasErrorInTemplate = true;
|
|
64
53
|
});
|
|
65
54
|
let newFile = lines.join(EOL);
|
|
66
55
|
if (hasErrorInTemplate) {
|
|
@@ -71,3 +60,31 @@ export function ignoreErrorsFallback(file, lintErrors) {
|
|
|
71
60
|
}
|
|
72
61
|
return newFile;
|
|
73
62
|
}
|
|
63
|
+
export function ignoreErrorsTemplateTag(file, lintErrors) {
|
|
64
|
+
const lines = file.split(EOL);
|
|
65
|
+
const templateTags = findTemplateTags(file);
|
|
66
|
+
lintErrors.forEach((lintError) => {
|
|
67
|
+
const { line, message } = lintError;
|
|
68
|
+
const templateTagIndex = templateTags.findIndex(({ lineRange }) => {
|
|
69
|
+
return lineRange.start <= line && line <= lineRange.end;
|
|
70
|
+
});
|
|
71
|
+
const erroredInTemplate = templateTagIndex >= 0;
|
|
72
|
+
if (!erroredInTemplate) {
|
|
73
|
+
ignoreError(lintError, {
|
|
74
|
+
ignoreDirective,
|
|
75
|
+
lines,
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const { contents, lineRange } = templateTags[templateTagIndex];
|
|
80
|
+
const currentIndex = line - 1;
|
|
81
|
+
const comment = `{{! @glint-expect-error: ${message} }}`;
|
|
82
|
+
if (lineRange.start < lineRange.end) {
|
|
83
|
+
lines.splice(currentIndex, 0, comment);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const newTemplate = lines[currentIndex].replace(/<template>(.+)<\/template>/, [`<template>${comment}`, `${contents}</template>`].join(EOL));
|
|
87
|
+
lines.splice(currentIndex, 1, newTemplate);
|
|
88
|
+
});
|
|
89
|
+
return lines.join(EOL);
|
|
90
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function getFilesWithErrors(filePathToData) {
|
|
2
|
+
const filesWithErrors = [];
|
|
3
|
+
filePathToData.forEach((data, filePath) => {
|
|
4
|
+
const lintErrors = [];
|
|
5
|
+
data.forEach((message, line) => {
|
|
6
|
+
lintErrors.push({
|
|
7
|
+
line,
|
|
8
|
+
message,
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
if (lintErrors.length === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
lintErrors.sort((a, b) => {
|
|
15
|
+
if (a.line < b.line) {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
if (b.line < a.line) {
|
|
19
|
+
return -1;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
});
|
|
23
|
+
filesWithErrors.push({
|
|
24
|
+
filePath,
|
|
25
|
+
lintErrors,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return filesWithErrors;
|
|
29
|
+
}
|
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
filePathToData.forEach((data, filePath) => {
|
|
5
|
-
const lintErrors = [];
|
|
6
|
-
data.forEach((message, line) => {
|
|
7
|
-
lintErrors.push({
|
|
8
|
-
line,
|
|
9
|
-
message,
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
if (lintErrors.length === 0) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
lintErrors.sort((a, b) => {
|
|
16
|
-
if (a.line < b.line) {
|
|
17
|
-
return 1;
|
|
18
|
-
}
|
|
19
|
-
if (b.line < a.line) {
|
|
20
|
-
return -1;
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
23
|
-
});
|
|
24
|
-
filesWithErrors.push({
|
|
25
|
-
filePath,
|
|
26
|
-
lintErrors,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
return filesWithErrors;
|
|
30
|
-
}
|
|
31
|
-
export function getMessage(rules) {
|
|
32
|
-
return Array.from(new Set(rules.sort())).join(', ');
|
|
33
|
-
}
|
|
34
|
-
export function getRelativePath(absoluteFilePath, projectRoot) {
|
|
35
|
-
return relative(projectRoot, absoluteFilePath).replaceAll(sep, '/');
|
|
36
|
-
}
|
|
1
|
+
export * from './get-files-with-errors.js';
|
|
2
|
+
export * from './get-message.js';
|
|
3
|
+
export * from './get-relative-path.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ignore-lint-errors",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Codemod to ignore lint errors per line",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@codemod-utils/ast-javascript": "^4.3.
|
|
26
|
+
"@codemod-utils/ast-javascript": "^4.3.2",
|
|
27
27
|
"@codemod-utils/ast-template": "^4.1.0",
|
|
28
28
|
"@codemod-utils/ast-template-tag": "^2.7.0",
|
|
29
29
|
"@codemod-utils/files": "^4.1.0",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"yargs": "^18.1.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@changesets/cli": "^
|
|
35
|
-
"@codemod-utils/tests": "^3.
|
|
36
|
-
"@ijlee2-frontend-configs/changesets": "^
|
|
37
|
-
"@ijlee2-frontend-configs/eslint-config-node": "^4.2.
|
|
38
|
-
"@ijlee2-frontend-configs/prettier": "^3.3.
|
|
34
|
+
"@changesets/cli": "^3.0.2",
|
|
35
|
+
"@codemod-utils/tests": "^3.3.0",
|
|
36
|
+
"@ijlee2-frontend-configs/changesets": "^3.0.2",
|
|
37
|
+
"@ijlee2-frontend-configs/eslint-config-node": "^4.2.4",
|
|
38
|
+
"@ijlee2-frontend-configs/prettier": "^3.3.4",
|
|
39
39
|
"@sondr3/minitest": "^0.1.2",
|
|
40
|
-
"@tsconfig/node22": "^22.0.
|
|
40
|
+
"@tsconfig/node22": "^22.0.6",
|
|
41
41
|
"@tsconfig/strictest": "^2.0.8",
|
|
42
42
|
"@types/node": "^22.20.1",
|
|
43
43
|
"@types/yargs": "^17.0.35",
|
|
44
|
-
"concurrently": "^10.0.
|
|
45
|
-
"eslint": "^10.
|
|
44
|
+
"concurrently": "^10.0.5",
|
|
45
|
+
"eslint": "^10.10.0",
|
|
46
46
|
"prettier": "^3.9.6",
|
|
47
47
|
"typescript": "^6.0.3"
|
|
48
48
|
},
|