Skip to content

Commit

Permalink
Merge 446ff37 into 74ddbf9
Browse files Browse the repository at this point in the history
  • Loading branch information
pull[bot] committed Mar 17, 2020
2 parents 74ddbf9 + 446ff37 commit 0afb4fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
10 changes: 6 additions & 4 deletions rules/catch-error-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const astUtils = require('eslint-ast-utils');
const avoidCapture = require('./utils/avoid-capture');
const getDocumentationUrl = require('./utils/get-documentation-url');
const renameIdentifier = require('./utils/rename-identifier');

// Matches `someObj.then([FunctionExpression | ArrowFunctionExpression])`
function isLintablePromiseCatch(node) {
Expand Down Expand Up @@ -38,7 +39,8 @@ const create = context => {
...context.options[0]
};

const {scopeManager} = context.getSourceCode();
const sourceCode = context.getSourceCode();
const {scopeManager} = sourceCode;

const {name} = options;
const caughtErrorsIgnorePattern = new RegExp(options.caughtErrorsIgnorePattern);
Expand All @@ -64,7 +66,7 @@ const create = context => {

if (node.type === 'Identifier') {
problem.fix = fixer => {
const fixings = [fixer.replaceText(node, expectedName)];
const nodes = [node];

const variables = scopeManager.getDeclaredVariables(scopeNode);
for (const variable of variables) {
Expand All @@ -73,11 +75,11 @@ const create = context => {
}

for (const reference of variable.references) {
fixings.push(fixer.replaceText(reference.identifier, expectedName));
nodes.push(reference.identifier);
}
}

return fixings;
return nodes.map(node => renameIdentifier(node, expectedName, fixer, sourceCode));
};
}

Expand Down
1 change: 0 additions & 1 deletion rules/no-keyword-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ module.exports = {
docs: {
url: getDocumentationUrl(__filename)
},
fixable: 'code',
schema,
messages: {
[MESSAGE_ID]: 'Do not prefix identifiers with keyword `{{keyword}}`.'
Expand Down
17 changes: 6 additions & 11 deletions rules/no-unreadable-array-destructuring.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
'use strict';
const getDocumentationUrl = require('./utils/get-documentation-url');

const isCommaFollowedWithComma = (element, index, array) => {
return element === null && array[index + 1] === null;
};
const message = 'Array destructuring may not contain consecutive ignored values.';
const isCommaFollowedWithComma = (element, index, array) =>
element === null && array[index + 1] === null;

const create = context => {
return {
ArrayPattern(node) {
const {elements} = node;
if (!elements || elements.length === 0) {
return;
}

if (elements.some(isCommaFollowedWithComma)) {
'ArrayPattern[elements.length>=3]': node => {
if (node.elements.some(isCommaFollowedWithComma)) {
context.report({
node,
message: 'Array destructuring may not contain consecutive ignored values.'
message
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/catch-error-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const ruleTester = avaRuleTester(test, {
}
});

const typescriptRuleTester = avaRuleTester(test, {
parser: require.resolve('@typescript-eslint/parser')
});

function invalidTestCase(options) {
if (typeof options === 'string') {
options = {code: options};
Expand Down Expand Up @@ -416,3 +420,13 @@ ruleTester.run('catch-error-name', rule, {
}
]
});

typescriptRuleTester.run('catch-error-name', rule, {
valid: [],
invalid: [
invalidTestCase({
code: 'promise.catch(function (err: Error) { console.log(err) })',
output: 'promise.catch(function (error: Error) { console.log(error) })'
})
]
});
9 changes: 8 additions & 1 deletion test/no-unreadable-array-destructuring.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ ruleTester.run('no-unreadable-array-destructuring', rule, {
'function foo([bar,]) {}',
'function foo([bar,,]) {}',
'function foo([bar,, baz,, qux]) {}',
'const [, ...rest] = parts;'
'const [, ...rest] = parts;',
// This is stupid, but valid code
'const [,,] = parts;'
],
invalid: [
{
Expand Down Expand Up @@ -68,6 +70,11 @@ ruleTester.run('no-unreadable-array-destructuring', rule, {
{
code: 'const [,,...rest] = parts;',
errors
},
// This is stupid, but valid code
{
code: 'const [,,,] = parts;',
errors
}
]
});

0 comments on commit 0afb4fc

Please sign in to comment.