Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Fix restrict-full-import (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Seccafien committed Apr 19, 2019
1 parent ff94c17 commit e65edcc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<!-- ## Unreleased -->

### Fixed

* `shopify/estrict-full-import` "empty" array pattern (eg: `const [, bar] = foo` errors ([#238](https://github.com/Shopify/eslint-plugin-shopify/pull/238))

### Added

* `shopify/react-hooks-strict-return` Restrict the number of returned items from React hooks. ([#237](https://github.com/Shopify/eslint-plugin-shopify/pull/237))
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/restrict-full-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
})) ||
(left.type === 'ArrayPattern' &&
left.elements.some((element) => {
return element.type === 'RestElement';
return element != null && element.type === 'RestElement';
}))
);
}
Expand Down
112 changes: 29 additions & 83 deletions tests/lib/rules/restrict-full-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ const parserOptions = {
const options = [['lodash']];

// prettier-ignore
const message = `Unexpected full import of restricted module '${options[0][0]}'.`;

function configFor(type) {
const message = `Unexpected full import of restricted module '${options[0][0]}'.`;

return {
parserOptions,
options,
errors: [
{
message,
type,
},
],
};
}

ruleTester.run('restrict-full-import', rule, {
valid: [
Expand All @@ -29,115 +43,47 @@ ruleTester.run('restrict-full-import', rule, {
invalid: [
{
code: 'import * as _ from "lodash";',
parserOptions,
options,
errors: [
{
message,
type: 'ImportDeclaration',
},
],
...configFor('ImportDeclaration'),
},
{
code: 'import _ from "lodash";',
parserOptions,
options,
errors: [
{
message,
type: 'ImportDeclaration',
},
],
...configFor('ImportDeclaration'),
},
{
code: 'import _, {chain} from "lodash";',
parserOptions,
options,
errors: [
{
message,
type: 'ImportDefaultSpecifier',
},
],
...configFor('ImportDefaultSpecifier'),
},
{
code: 'import {default as _, chain} from "lodash";',
parserOptions,
options,
errors: [
{
message,
type: 'ImportSpecifier',
},
],
...configFor('ImportSpecifier'),
},
{
code: 'var _ = require("lodash");',
parserOptions,
options,
errors: [
{
message,
type: 'VariableDeclarator',
},
],
...configFor('VariableDeclarator'),
},
{
code: 'var _; _ = require("lodash");',
parserOptions,
options,
errors: [
{
message,
type: 'AssignmentExpression',
},
],
...configFor('AssignmentExpression'),
},
{
code: 'var {chain, ...rest} = require("lodash");',
parserOptions,
options,
errors: [
{
message,
type: 'VariableDeclarator',
},
],
...configFor('VariableDeclarator'),
},
{
code: 'var {chain, ...rest} = require("lodash");',
parserOptions,
options,
parser: 'babel-eslint',
errors: [
{
message,
type: 'VariableDeclarator',
},
],
...configFor('VariableDeclarator'),
},
{
code: 'var [chain, ...rest] = require("lodash");',
parserOptions,
options,
errors: [
{
message,
type: 'VariableDeclarator',
},
],
...configFor('VariableDeclarator'),
},
{
code: 'var [chain, ...rest] = require("lodash");',
parserOptions,
options,
parser: 'babel-eslint',
errors: [
{
message,
type: 'VariableDeclarator',
},
],
...configFor('VariableDeclarator'),
},
{
code: 'var [, , ...rest] = require("lodash");',
...configFor('VariableDeclarator'),
},
],
});

0 comments on commit e65edcc

Please sign in to comment.