Skip to content

Commit

Permalink
Add eslint rules to guard against unexpected imports/exports (#28513)
Browse files Browse the repository at this point in the history
* Add eslint-plugin-import and enable default and named rules

* Fix the rest errors

* Update changelog

* Warn it first to prevent breaking change

* Add eslint-plugin-import to root devDeps

* Fix code reviews
  • Loading branch information
kevin940726 authored Feb 1, 2021
1 parent d9e7541 commit d63f9a1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module.exports = {
},
],
'@wordpress/no-unsafe-wp-apis': 'off',
'import/default': 'error',
'import/named': 'error',
'no-restricted-imports': [
'error',
{
Expand Down Expand Up @@ -152,6 +154,7 @@ module.exports = {
rules: {
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'off',
'import/named': 'off',
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"enzyme": "3.11.0",
"equivalent-key-map": "0.2.2",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.22.1",
"execa": "4.0.2",
"fast-glob": "2.2.7",
"glob": "7.1.2",
Expand Down
8 changes: 5 additions & 3 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {

import * as selectors from '../selectors';
import reducer from '../reducer';
import actions, {
import * as actions from '../actions';
import '../..';

const {
clearSelectedBlock,
enterFormattedText,
exitFormattedText,
Expand Down Expand Up @@ -55,8 +58,7 @@ import actions, {
updateSettings,
selectionChange,
validateBlocksToTemplate,
} from '../actions';
import '../..';
} = actions;

describe( 'actions', () => {
const defaultBlockSettings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ class TokenFieldWrapper extends Component {
}
}

module.exports = TokenFieldWrapper;
export default TokenFieldWrapper;
4 changes: 4 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New Features

- Enabled `import/default` and `import/named` rules in the `recommended` ruleset. [#28513](https://github.com/WordPress/gutenberg/pull/28513)

## 8.0.1 (2021-01-28)

### Bug Fix
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/configs/recommended-with-formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module.exports = {
},
],
'import/no-unresolved': 'error',
'import/default': 'warn',
'import/named': 'warn',
},
overrides: [
{
Expand Down

0 comments on commit d63f9a1

Please sign in to comment.