You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
'use strict';
|
|
const getDocumentationUrl = require('./utils/get-documentation-url');
|
|
const {findVariable, isOpeningParenToken, isClosingParenToken} = require('eslint-utils');
|
|
|
|
const ERROR_MESSAGE_ID = 'error';
|
|
|
|
const selector = [
|
|
'CatchClause',
|
|
'>',
|
|
'Identifier.param'
|
|
].join('');
|
|
|
|
const create = context => {
|
|
return {
|
|
[selector]: node => {
|
|
const scope = context.getScope();
|
|
const variable = findVariable(scope, node);
|
|
|
|
if (variable.references.length !== 0) {
|
|
return;
|
|
}
|
|
|
|
const {name} = node;
|
|
|
|
context.report({
|
|
node,
|
|
messageId: ERROR_MESSAGE_ID,
|
|
data: {name},
|
|
fix: fixer => {
|
|
const tokenBefore = context.getTokenBefore(node);
|
|
const tokenAfter = context.getTokenAfter(node);
|
|
|
|
/* istanbul ignore next */
|
|
if (!isOpeningParenToken(tokenBefore) || !isClosingParenToken(tokenAfter)) {
|
|
throw new Error('Unexpected token.');
|
|
}
|
|
|
|
return [
|
|
tokenBefore,
|
|
node,
|
|
tokenAfter
|
|
].map(nodeOrToken => fixer.remove(nodeOrToken));
|
|
}
|
|
});
|
|
}
|
|
};
|
|
};
|
|
|
|
module.exports = {
|
|
create,
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: getDocumentationUrl(__filename)
|
|
},
|
|
fixable: 'code',
|
|
messages: {
|
|
[ERROR_MESSAGE_ID]: 'Remove unused catch binding `{{name}}`.'
|
|
}
|
|
}
|
|
};
|