mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: implement code fix for 'use-using' rule (#10805)
This commit is contained in:
parent
2401bb46b1
commit
cb5ab7e02f
@ -15,10 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {ESLintUtils, TSESTree} from '@typescript-eslint/utils';
|
import {ESLintUtils, TSESTree} from '@typescript-eslint/utils';
|
||||||
import type {
|
|
||||||
RuleListener,
|
|
||||||
RuleModule,
|
|
||||||
} from '@typescript-eslint/utils/ts-eslint';
|
|
||||||
|
|
||||||
const usingSymbols = ['ElementHandle', 'JSHandle'];
|
const usingSymbols = ['ElementHandle', 'JSHandle'];
|
||||||
|
|
||||||
@ -26,18 +22,17 @@ const createRule = ESLintUtils.RuleCreator(name => {
|
|||||||
return `https://github.com/puppeteer/puppeteer/tree/main/tools/eslint/${name}.js`;
|
return `https://github.com/puppeteer/puppeteer/tree/main/tools/eslint/${name}.js`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
const useUsingRule = createRule<[], 'useUsing' | 'useUsingFix'>({
|
||||||
[],
|
|
||||||
'useUsing'
|
|
||||||
>({
|
|
||||||
name: 'use-using',
|
name: 'use-using',
|
||||||
meta: {
|
meta: {
|
||||||
docs: {
|
docs: {
|
||||||
description: "Requires 'using' for element/JS handles.",
|
description: "Requires 'using' for element/JS handles.",
|
||||||
requiresTypeChecking: true,
|
requiresTypeChecking: true,
|
||||||
},
|
},
|
||||||
|
hasSuggestions: true,
|
||||||
messages: {
|
messages: {
|
||||||
useUsing: "Use 'using'.",
|
useUsing: "Use 'using'.",
|
||||||
|
useUsingFix: "Replace with 'using' to ignore.",
|
||||||
},
|
},
|
||||||
schema: [],
|
schema: [],
|
||||||
type: 'problem',
|
type: 'problem',
|
||||||
@ -49,7 +44,7 @@ const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
VariableDeclaration(node): void {
|
VariableDeclaration(node): void {
|
||||||
if (['using', 'await using'].includes(node.kind)) {
|
if (['using', 'await using'].includes(node.kind) || node.declare) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const declaration of node.declarations) {
|
for (const declaration of node.declarations) {
|
||||||
@ -77,6 +72,17 @@ const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
|||||||
context.report({
|
context.report({
|
||||||
node: declaration.id,
|
node: declaration.id,
|
||||||
messageId: 'useUsing',
|
messageId: 'useUsing',
|
||||||
|
suggest: [
|
||||||
|
{
|
||||||
|
messageId: 'useUsingFix',
|
||||||
|
fix(fixer) {
|
||||||
|
return fixer.replaceTextRange(
|
||||||
|
[node.range[0], node.range[0] + node.kind.length],
|
||||||
|
'using'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user