Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint: Copy no-restricted-syntax rules from ESLint plugin to config file #15877

Merged
merged 1 commit into from
May 29, 2019

Conversation

tfrommen
Copy link
Member

Description

As discussed in #15839, this PR copies the custom rules/options to the Gutenberg ESLint config.

How has this been tested?

Create a file test.js with this content:

const { __experimentalGetSettings } = wp.date;
const { __, _n, _nx, _x } = wp.i18n;

const foo_x = () => {};

const foo = 'bar';

/**
 * Should NOT flag
 */
__( 'Some text', 'text-domain' );
_n( 'Some text', 'Some texts', 42, 'text-domain' );
_nx( 'Some text', 'Some texts', 42, 'Some context', 'text-domain' );
_x( 'Some text', 'Some context', 'text-domain' );
const settings = __experimentalGetSettings();
foo_x();

/**
 * SHOULD flag
 */
__( foo, 'text-domain' );
_n( foo, 'Some texts', 42, 'text-domain' );
_nx( foo, 'Some texts', 42, 'Some context', 'text-domain' );
_x( foo, 'Some context', 'text-domain' );

_n( 'Some text', foo, 42, 'text-domain' );
_nx( 'Some texts', foo, 42, 'Some context', 'text-domain' );
_x( 'Some text', foo, 'text-domain' );

_nx( 'Some text', 'Some texts', 42, foo, 'text-domain' );

Then call:

./node_modules/.bin/eslint test.js

Types of changes

Copy ESLint rules/options that are defined in the ESLint plugin, but overriden in the Gutenberg ESLint config.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@tfrommen tfrommen added [Type] Bug An existing feature does not function as intended [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels May 29, 2019
@tfrommen tfrommen self-assigned this May 29, 2019
@gziolo gziolo added this to the 5.9 (Gutenberg) milestone May 29, 2019
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for wrangling it. Let's merge when Travis is green.

@@ -1,7 +1,7 @@
/**
* External dependencies
*/
const { escapeRegExp, map } = require( 'lodash' );
const { escapeRegExp } = require( 'lodash' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's surprising, it should error in master...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ./node_modules/.bin/eslint .eslintrc.js

/Users/pascalb/Workspace/WordPress/gutenberg/.eslintrc.js
  0:0  warning  File ignored by default.  Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'") to override

✖ 1 problem (0 errors, 1 warning)

That explains it :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same, but reason is that the .eslintrc.js file is, by default, ignored. So ESLint doesn't check it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good to know 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same, but reason is that the .eslintrc.js file is, by default, ignored. So ESLint doesn't check it.

Can we change this? Not immediately obvious why we'd want it to be exempt.

Copy link
Member Author

@tfrommen tfrommen May 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth sure, I'll create a PR for that. See #15887.

@gziolo gziolo merged commit 48afde8 into master May 29, 2019
@gziolo gziolo deleted the translate-function-arguments-eslint-rules branch May 29, 2019 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants