Skip to content

Commit d91e55f

Browse files
committed
feature: @putout/plugin-eslint: remove-parser-options: typescript: false positive
1 parent d6f89fb commit d91e55f

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

packages/plugin-eslint/lib/remove-parser-options/fixture/typescript-options.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ const options = {
88
}
99
}
1010
};
11+
12+
const options2 = {
13+
languageOptions: {
14+
parserOptions: {
15+
projectService: true,
16+
}
17+
},
18+
};
19+
20+
const options3 = {
21+
languageOptions: {
22+
parserOptions: {
23+
tsconfigRootDir: import.meta.dirname
24+
}
25+
},
26+
};

packages/plugin-eslint/lib/remove-parser-options/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {operator} from 'putout';
22

3+
const {keys} = Object;
34
const {
45
traverseProperties,
6+
getProperties,
57
replaceWith,
68
} = operator;
79

8-
export const report = () => `Avoid "parserOptions" in FlatConfig`;
10+
export const report = () => `Avoid 'parserOptions' in FlatConfig`;
911

1012
export const fix = (path) => {
1113
replaceWith(path.parentPath, path.node.value);
@@ -28,10 +30,18 @@ export const traverse = ({push}) => ({
2830
if (parserPath)
2931
return false;
3032

31-
const [babelOptionsPath] = traverseProperties(parserOptionsPath, 'babelOptions');
32-
const [ecmaFeatures] = traverseProperties(parserOptionsPath, 'ecmaFeatures');
33+
const names = [
34+
'babelOptions',
35+
'ecmaFeatures',
36+
'projectService',
37+
'tsconfigRootDir',
38+
];
3339

34-
if (ecmaFeatures || babelOptionsPath)
40+
const parserOptionsValuePath = parserOptionsPath.get('value');
41+
const properties = getProperties(parserOptionsValuePath, names);
42+
const count = keys(properties).length;
43+
44+
if (count)
3545
return;
3646

3747
push(parserOptionsPath);

packages/plugin-eslint/lib/remove-parser-options/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const test = createTest(import.meta.url, {
88
});
99

1010
test('eslint: remove-parser-options: report', (t) => {
11-
t.report('remove-parser-options', `Avoid "parserOptions" in FlatConfig`);
11+
t.report('remove-parser-options', `Avoid 'parserOptions' in FlatConfig`);
1212
t.end();
1313
});
1414

0 commit comments

Comments
 (0)