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 type {
|
||||
RuleListener,
|
||||
RuleModule,
|
||||
} from '@typescript-eslint/utils/ts-eslint';
|
||||
|
||||
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`;
|
||||
});
|
||||
|
||||
const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
||||
[],
|
||||
'useUsing'
|
||||
>({
|
||||
const useUsingRule = createRule<[], 'useUsing' | 'useUsingFix'>({
|
||||
name: 'use-using',
|
||||
meta: {
|
||||
docs: {
|
||||
description: "Requires 'using' for element/JS handles.",
|
||||
requiresTypeChecking: true,
|
||||
},
|
||||
hasSuggestions: true,
|
||||
messages: {
|
||||
useUsing: "Use 'using'.",
|
||||
useUsingFix: "Replace with 'using' to ignore.",
|
||||
},
|
||||
schema: [],
|
||||
type: 'problem',
|
||||
@ -49,7 +44,7 @@ const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
||||
|
||||
return {
|
||||
VariableDeclaration(node): void {
|
||||
if (['using', 'await using'].includes(node.kind)) {
|
||||
if (['using', 'await using'].includes(node.kind) || node.declare) {
|
||||
return;
|
||||
}
|
||||
for (const declaration of node.declarations) {
|
||||
@ -77,6 +72,17 @@ const useUsingRule: RuleModule<'useUsing', [], RuleListener> = createRule<
|
||||
context.report({
|
||||
node: declaration.id,
|
||||
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