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: set line width to 80 #19992

Merged
merged 4 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 40 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const { version } = require( './package' );
*
* @type {string}
*/
const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?';
const majorMinorRegExp =
escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\.\\d+)?';

/**
* The list of patterns matching files used only for development purposes.
Expand All @@ -29,7 +30,10 @@ const developmentFiles = [

module.exports = {
root: true,
extends: [ 'plugin:@wordpress/eslint-plugin/recommended', 'plugin:eslint-comments/recommended' ],
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
'plugin:eslint-comments/recommended',
],
plugins: [ 'import' ],
globals: {
wp: 'off',
Expand All @@ -44,37 +48,46 @@ module.exports = {
// we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern)
// here. That's why we use \\u002F in the regexes below.
{
selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
message: 'Path access on WordPress dependencies is not allowed.',
selector:
'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
message:
'Path access on WordPress dependencies is not allowed.',
},
{
selector: 'ImportDeclaration[source.value=/^react-spring(?!\\u002Fweb.cjs)/]',
message: 'The react-spring dependency must specify CommonJS bundle: react-spring/web.cjs',
selector:
'ImportDeclaration[source.value=/^react-spring(?!\\u002Fweb.cjs)/]',
message:
'The react-spring dependency must specify CommonJS bundle: react-spring/web.cjs',
},
{
selector:
'CallExpression[callee.name="deprecated"] Property[key.name="version"][value.value=/' +
majorMinorRegExp +
'/]',
message: 'Deprecated functions must be removed before releasing this version.',
message:
'Deprecated functions must be removed before releasing this version.',
},
{
selector:
'CallExpression[callee.name=/^(__|_n|_nx|_x)$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
message:
'Translate function arguments must be string literals.',
},
{
selector:
'CallExpression[callee.name=/^(_n|_nx|_x)$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
message:
'Translate function arguments must be string literals.',
},
{
selector:
'CallExpression[callee.name=_nx]:not([arguments.3.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
message:
'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]',
selector:
'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]',
message: 'Use ellipsis character (…) in place of three dots',
},
{
Expand All @@ -83,22 +96,26 @@ module.exports = {
message: 'Use `combineReducers` from `@wordpress/data`',
},
{
selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]',
selector:
'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]',
message: 'Use memize instead of Lodash’s memoize',
},
{
selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
selector:
'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
message: 'Prefer page.waitForSelector instead.',
},
{
selector: 'JSXAttribute[name.name="id"][value.type="Literal"]',
message: 'Do not use string literals for IDs; use withInstanceId instead.',
message:
'Do not use string literals for IDs; use withInstanceId instead.',
},
{
// Discourage the usage of `Math.random()` as it's a code smell
// for UUID generation, for which we already have a higher-order
// component: `withInstanceId`.
selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]',
selector:
'CallExpression[callee.object.name="Math"][callee.property.name="random"]',
message:
'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you’re not generating unique IDs: ignore this message.)',
},
Expand All @@ -119,14 +136,20 @@ module.exports = {
overrides: [
{
files: [ 'packages/**/*.js' ],
excludedFiles: [ '**/*.@(android|ios|native).js', ...developmentFiles ],
excludedFiles: [
'**/*.@(android|ios|native).js',
...developmentFiles,
],
rules: {
'import/no-extraneous-dependencies': 'error',
},
},
{
files: [ 'packages/**/*.js' ],
excludedFiles: [ 'packages/block-library/src/*/save.js', ...developmentFiles ],
excludedFiles: [
'packages/block-library/src/*/save.js',
...developmentFiles,
],
rules: {
'react/forbid-elements': [
'error',
Expand Down
4 changes: 3 additions & 1 deletion bin/api-docs/are-readmes-unstaged.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const getUnstagedFiles = () =>
const readmeFiles = getPackages().map( ( [ packageName ] ) =>
join( 'packages', packageName, 'README.md' )
);
const unstagedReadmes = getUnstagedFiles().filter( ( element ) => readmeFiles.includes( element ) );
const unstagedReadmes = getUnstagedFiles().filter( ( element ) =>
readmeFiles.includes( element )
);

if ( unstagedReadmes.length > 0 ) {
process.exitCode = 1;
Expand Down
9 changes: 8 additions & 1 deletion bin/api-docs/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ getPackages().forEach( ( entry ) => {
// Each target operates over the same file, so it needs to be processed synchronously,
// as to make sure the processes don't overwrite each other.
const { status, stderr } = spawnSync(
join( __dirname, '..', '..', 'node_modules', '.bin', 'docgen' ).replace( / /g, '\\ ' ),
join(
__dirname,
'..',
'..',
'node_modules',
'.bin',
'docgen'
).replace( / /g, '\\ ' ),
[
join( 'packages', packageName, path ),
`--output packages/${ packageName }/README.md`,
Expand Down
Loading