Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 19, 2022
1 parent b773f14 commit 812417f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 65 deletions.
51 changes: 31 additions & 20 deletions src/rules/no-unused-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ import type { AST, Rule } from 'eslint';
import type { Loc } from 'pug-lexer';
import { processRule } from '../utils';

const DECLARATION_DIRECTIVES: string[] = ['v-for', 'scope', 'slot-scope', 'v-slot'];
const DECLARATION_DIRECTIVES: string[] = [
'v-for',
'scope',
'slot-scope',
'v-slot',
];

export default {
meta: {
hasSuggestions: true,
type: 'suggestion',
docs: {
description: 'disallow unused variable definitions of v-for directives or scope attributes',
description:
'disallow unused variable definitions of v-for directives or scope attributes',
categories: ['vue3-essential', 'essential'],
url: 'https://eslint.vuejs.org/rules/no-unused-vars.html'
url: 'https://eslint.vuejs.org/rules/no-unused-vars.html',
},
fixable: undefined,
schema: [
{
type: 'object',
properties: {
ignorePattern: {
type: 'string'
}
type: 'string',
},
},
additionalProperties: false
}
]
additionalProperties: false,
},
],
},
create(context) {
return processRule(context, () => {
Expand All @@ -47,9 +53,14 @@ export default {
// TODO: decrease indentation level
},
attribute(token) {
if (DECLARATION_DIRECTIVES.includes(token.name) && typeof token.val === 'string') {
const match: RegExpExecArray | null = /(?<variableGroup>.+) (in|of) .+/.exec(token.val.slice(1, -1));
const variableGroup: string | undefined = match?.groups?.variableGroup;
if (
DECLARATION_DIRECTIVES.includes(token.name) &&
typeof token.val === 'string'
) {
const match: RegExpExecArray | null =
/(?<variableGroup>.+) (in|of) .+/.exec(token.val.slice(1, -1));
const variableGroup: string | undefined =
match?.groups?.variableGroup;
console.log('variableGroup', variableGroup);
}

Expand All @@ -67,16 +78,16 @@ export default {
column: loc.start.column - 1,
start: {
line: loc.start.line,
column: columnStart
column: columnStart,
},
end: {
line: loc.end.line,
column: columnEnd
}
column: columnEnd,
},
},
message: "'{{name}}' is defined but never used.",
data: {
name: variableName
name: variableName,
},
suggest:
ignorePattern === '^_'
Expand All @@ -87,13 +98,13 @@ export default {
// @ts-expect-error: Access token range
const range: AST.Range = token.range;
return fixer.insertTextBeforeRange(range, '_');
}
}
},
},
]
: []
: [],
});
}
},
};
});
}
},
} as Rule.RuleModule;
Loading

0 comments on commit 812417f

Please sign in to comment.