ignore-lint-errors 0.1.0
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/LICENSE.md +9 -0
- package/README.md +56 -0
- package/dist/bin/ignore-lint-errors.js +25 -0
- package/dist/src/index.js +6 -0
- package/dist/src/steps/create-options.js +7 -0
- package/dist/src/steps/ignore-errors/eslint.js +22 -0
- package/dist/src/steps/ignore-errors/index.js +1 -0
- package/dist/src/steps/ignore-errors.js +10 -0
- package/dist/src/steps/index.js +3 -0
- package/dist/src/steps/lint-files/eslint.js +11 -0
- package/dist/src/steps/lint-files/index.js +1 -0
- package/dist/src/steps/lint-files.js +16 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/linters/eslint.js +49 -0
- package/package.json +55 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[](https://github.com/ijlee2/ignore-lint-errors/actions/workflows/ci.yml)
|
|
2
|
+
|
|
3
|
+
# ignore-lint-errors
|
|
4
|
+
|
|
5
|
+
_Codemod to add ignore directives_
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
### Arguments
|
|
11
|
+
|
|
12
|
+
[PROVIDE REQUIRED AND OPTIONAL ARGUMENTS.]
|
|
13
|
+
|
|
14
|
+
<details>
|
|
15
|
+
|
|
16
|
+
<summary>Optional: Specify the project root</summary>
|
|
17
|
+
|
|
18
|
+
Pass `--root` to run the codemod somewhere else (i.e. not in the current directory).
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpx ignore-lint-errors --root <path/to/your/project>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
</details>
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Limitations
|
|
28
|
+
|
|
29
|
+
The codemod is designed to cover typical cases. It is not designed to cover one-off cases.
|
|
30
|
+
|
|
31
|
+
To better meet your needs, consider cloning the repo and running the codemod locally.
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
cd <path/to/cloned/repo>
|
|
35
|
+
|
|
36
|
+
# Compile TypeScript
|
|
37
|
+
pnpm build
|
|
38
|
+
|
|
39
|
+
# Run codemod
|
|
40
|
+
./dist/bin/ignore-lint-errors.js --root <path/to/your/project>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Compatibility
|
|
45
|
+
|
|
46
|
+
- Node.js v22 or above
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Contributing
|
|
50
|
+
|
|
51
|
+
See the [Contributing](./CONTRIBUTING.md) guide for details.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
This project is licensed under the [MIT License](./LICENSE.md).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
import yargs from 'yargs';
|
|
4
|
+
import { hideBin } from 'yargs/helpers';
|
|
5
|
+
import { runCodemod } from '../src/index.js';
|
|
6
|
+
// Provide a title to the process in `ps`
|
|
7
|
+
process.title = 'ignore-lint-errors';
|
|
8
|
+
// Set codemod options
|
|
9
|
+
const argv = yargs(hideBin(process.argv))
|
|
10
|
+
.option('linter', {
|
|
11
|
+
choices: ['eslint'],
|
|
12
|
+
describe: 'Linter to run',
|
|
13
|
+
type: 'string',
|
|
14
|
+
})
|
|
15
|
+
.option('root', {
|
|
16
|
+
describe: 'Where to run the codemod',
|
|
17
|
+
type: 'string',
|
|
18
|
+
})
|
|
19
|
+
.demandOption(['linter'])
|
|
20
|
+
.parseSync();
|
|
21
|
+
const codemodOptions = {
|
|
22
|
+
linter: argv['linter'],
|
|
23
|
+
projectRoot: argv['root'] ?? process.cwd(),
|
|
24
|
+
};
|
|
25
|
+
runCodemod(codemodOptions);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { removeFiles } from '@codemod-utils/files';
|
|
4
|
+
import { outputFilePath, parseOutputFile } from '../../utils/linters/eslint.js';
|
|
5
|
+
export function ignoreErrorsFromEslint(options) {
|
|
6
|
+
const { projectRoot } = options;
|
|
7
|
+
if (!existsSync(join(projectRoot, outputFilePath))) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const outputFile = readFileSync(join(projectRoot, outputFilePath), 'utf8');
|
|
11
|
+
const filesWithErrors = parseOutputFile(outputFile);
|
|
12
|
+
filesWithErrors.forEach(({ absoluteFilePath, lintErrors }) => {
|
|
13
|
+
const file = readFileSync(absoluteFilePath, 'utf8');
|
|
14
|
+
const lines = file.split('\n');
|
|
15
|
+
lintErrors.forEach(({ line, message }) => {
|
|
16
|
+
const ignoreDirective = `// @ts-expect-error: ${message}`;
|
|
17
|
+
lines.splice(line - 1, 0, ignoreDirective);
|
|
18
|
+
});
|
|
19
|
+
writeFileSync(absoluteFilePath, lines.join('\n'), 'utf8');
|
|
20
|
+
});
|
|
21
|
+
removeFiles([outputFilePath], { projectRoot });
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './eslint.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { command } from '../../utils/linters/eslint.js';
|
|
3
|
+
export function runEslint(options) {
|
|
4
|
+
const { projectRoot } = options;
|
|
5
|
+
try {
|
|
6
|
+
execSync(command, { cwd: projectRoot });
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
// Do nothing
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './eslint.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { runEslint } from './lint-files/index.js';
|
|
4
|
+
export function lintFiles(options) {
|
|
5
|
+
const { linter, projectRoot } = options;
|
|
6
|
+
const tempDir = '.ignore-lint-errors';
|
|
7
|
+
if (!existsSync(join(projectRoot, tempDir))) {
|
|
8
|
+
mkdirSync(join(projectRoot, tempDir));
|
|
9
|
+
}
|
|
10
|
+
switch (linter) {
|
|
11
|
+
case 'eslint': {
|
|
12
|
+
runEslint(options);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const outputFilePath = '.ignore-lint-errors/eslint.txt';
|
|
2
|
+
export const command = [
|
|
3
|
+
'./node_modules/.bin/eslint',
|
|
4
|
+
'--format json',
|
|
5
|
+
`--output-file ${outputFilePath}`,
|
|
6
|
+
'--quiet',
|
|
7
|
+
].join(' ');
|
|
8
|
+
export function parseOutputFile(file) {
|
|
9
|
+
const filePathToData = new Map();
|
|
10
|
+
const records = JSON.parse(file);
|
|
11
|
+
records.forEach((record) => {
|
|
12
|
+
const { filePath: absoluteFilePath, messages } = record;
|
|
13
|
+
const data = new Map();
|
|
14
|
+
messages.forEach(({ line, ruleId }) => {
|
|
15
|
+
if (data.has(line)) {
|
|
16
|
+
data.get(line).push(ruleId);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
data.set(line, [ruleId]);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
filePathToData.set(absoluteFilePath, data);
|
|
23
|
+
});
|
|
24
|
+
const filesWithErrors = [];
|
|
25
|
+
filePathToData.forEach((data, absoluteFilePath) => {
|
|
26
|
+
const lintErrors = [];
|
|
27
|
+
data.forEach((allMessages, line) => {
|
|
28
|
+
const ruleIds = Array.from(new Set(allMessages.sort()));
|
|
29
|
+
lintErrors.push({
|
|
30
|
+
line,
|
|
31
|
+
message: ruleIds.join(', '),
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
lintErrors.sort((a, b) => {
|
|
35
|
+
if (a.line < b.line) {
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
if (b.line < a.line) {
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
});
|
|
43
|
+
filesWithErrors.push({
|
|
44
|
+
absoluteFilePath,
|
|
45
|
+
lintErrors,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return filesWithErrors;
|
|
49
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ignore-lint-errors",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Codemod to add ignore directives",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"codemod",
|
|
7
|
+
"ember-codemod",
|
|
8
|
+
"emberjs"
|
|
9
|
+
],
|
|
10
|
+
"repository": "",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "dist/src/index.js",
|
|
15
|
+
"bin": "dist/bin/ignore-lint-errors.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@codemod-utils/files": "^4.0.1",
|
|
21
|
+
"yargs": "^18.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@changesets/cli": "^2.30.0",
|
|
25
|
+
"@codemod-utils/tests": "^3.0.1",
|
|
26
|
+
"@ijlee2-frontend-configs/changesets": "^2.1.0",
|
|
27
|
+
"@ijlee2-frontend-configs/eslint-config-node": "^3.2.0",
|
|
28
|
+
"@ijlee2-frontend-configs/prettier": "^3.0.2",
|
|
29
|
+
"@sondr3/minitest": "^0.1.2",
|
|
30
|
+
"@tsconfig/node22": "^22.0.5",
|
|
31
|
+
"@tsconfig/strictest": "^2.0.8",
|
|
32
|
+
"@types/node": "^22.19.17",
|
|
33
|
+
"@types/yargs": "^17.0.35",
|
|
34
|
+
"concurrently": "^9.2.1",
|
|
35
|
+
"eslint": "^9.39.4",
|
|
36
|
+
"prettier": "^3.8.3",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": "22.* || >= 24"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "sh build.sh --production",
|
|
44
|
+
"format": "prettier . --cache --write",
|
|
45
|
+
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\"",
|
|
46
|
+
"lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" && pnpm format",
|
|
47
|
+
"lint:format": "prettier . --cache --check",
|
|
48
|
+
"lint:js": "eslint . --cache",
|
|
49
|
+
"lint:js:fix": "eslint . --fix",
|
|
50
|
+
"lint:types": "tsc --noEmit",
|
|
51
|
+
"release:prepare": "changeset version",
|
|
52
|
+
"release:publish": "pnpm build && changeset publish",
|
|
53
|
+
"test": "sh build.sh --test && mt dist-for-testing --quiet"
|
|
54
|
+
}
|
|
55
|
+
}
|