Skip to content

Commit

Permalink
chore(lint): add eslint-plugin-eslint-plugin internally and fix viola…
Browse files Browse the repository at this point in the history
…tions

This PR adds [eslint-plugin-eslint-plugin](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin) (a popular plugin for linting eslint plugins), enables relevant rules from it, and fixes violations.

The primary changes included are:
1. Adds missing rule schemas ([require-meta-schema](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-schema.md)). Note that `schema: []` is added to enforce when a rule should have no schema.
2. Adds missing rule `type` property to `no-unused-modules` rule ([require-meta-type](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-type.md)).
3. Removes duplicate test cases ([no-identical-tests](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-identical-tests.md)).
4. Switches some test cases to use the string shorthand ([test-case-shorthand-strings](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/test-case-shorthand-strings.md)).
  • Loading branch information
bmish committed Jan 20, 2020
1 parent f84d457 commit d296ecf
Show file tree
Hide file tree
Showing 32 changed files with 64 additions and 43 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
plugins:
- eslint-plugin
- import
extends:
- eslint:recommended
- plugin:eslint-plugin/recommended
- plugin:import/recommended

env:
Expand All @@ -26,6 +28,17 @@ rules:
- allowTemplateLiterals: true
avoidEscape: true

eslint-plugin/consistent-output: "error"
eslint-plugin/meta-property-ordering: "error"
eslint-plugin/no-deprecated-context-methods: "error"
eslint-plugin/no-deprecated-report-api: "off"
eslint-plugin/prefer-output-null: "error"
eslint-plugin/prefer-replace-text: "error"
eslint-plugin/report-message-format: "error"
eslint-plugin/require-meta-schema: "error"
eslint-plugin/require-meta-type: "error"
eslint-plugin/test-case-shorthand-strings: "error"

# dog fooding
import/no-extraneous-dependencies: "error"
import/unambiguous: "off"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`extensions`]: for invalid code where `name` does not exist, do not crash ([#1613], thanks [@ljharb])
- [`extentions`]: Fix scope regex ([#1611], thanks [@yordis])
- [`no-duplicates`]: allow duplicate imports if one is a namespace and the other not ([#1612], thanks [@sveyret])
- Add some missing rule meta schemas and types ([#1620], thanks [@bmish])

### Changed
- [`import/external-module-folders` setting] behavior is more strict now: it will only match complete path segments ([#1605], thanks [@skozin])
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
"eslint-module-utils": "file:./utils",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-import": "2.x",
"linklocal": "^2.8.2",
"mocha": "^3.5.3",
Expand Down
1 change: 1 addition & 0 deletions src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
docs: {
url: docsUrl('default'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
docs: {
url: docsUrl('export'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/exports-last.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
docs: {
url: docsUrl('exports-last'),
},
schema: [],
},

create: function (context) {
Expand Down
6 changes: 6 additions & 0 deletions src/rules/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = {
url: docsUrl('first'),
},
fixable: 'code',
schema: [
{
type: 'string',
enum: ['absolute-first'],
},
],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
docs: {
url: docsUrl('named'),
},
schema: [],
},

create: function (context) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
docs: {
url: docsUrl('newline-after-import'),
},
fixable: 'whitespace',
schema: [
{
'type': 'object',
Expand All @@ -61,7 +62,6 @@ module.exports = {
'additionalProperties': false,
},
],
fixable: 'whitespace',
},
create: function (context) {
let level = 0
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
docs: {
url: docsUrl('no-amd'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: {},
schema: [],
},

create(context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
docs: {
url: docsUrl('no-deprecated'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-dynamic-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
docs: {
url: docsUrl('no-dynamic-require'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-mutable-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
docs: {
url: docsUrl('no-mutable-exports'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-named-as-default-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
docs: {
url: docsUrl('no-named-as-default-member'),
},
schema: [],
},

create: function(context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
docs: {
url: docsUrl('no-named-as-default'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-named-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
docs: {
url: docsUrl('no-named-default'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-named-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
meta: {
type: 'suggestion',
docs: { url: docsUrl('no-named-export') },
schema: [],
},

create(context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
url: docsUrl('no-namespace'),
},
fixable: 'code',
schema: [],
},

create: function (context) {
Expand Down
11 changes: 11 additions & 0 deletions src/rules/no-nodejs-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ module.exports = {
docs: {
url: docsUrl('no-nodejs-modules'),
},
schema: [
{
type: 'object',
properties: {
allow: {
type: 'array',
},
},
additionalProperties: false,
},
],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const fileIsInPkg = file => {

module.exports = {
meta: {
type: 'suggestion',
docs: { url: docsUrl('no-unused-modules') },
schema: [{
properties: {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module.exports = {
url: docsUrl('no-useless-path-segments'),
},

fixable: 'code',

schema: [
{
type: 'object',
Expand All @@ -53,8 +55,6 @@ module.exports = {
additionalProperties: false,
},
],

fixable: 'code',
},

create(context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/no-webpack-loader-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
docs: {
url: docsUrl('no-webpack-loader-syntax'),
},
schema: [],
},

create: function (context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/prefer-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
docs: {
url: docsUrl('prefer-default-export'),
},
schema: [],
},

create: function(context) {
Expand Down
1 change: 1 addition & 0 deletions src/rules/unambiguous.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
docs: {
url: docsUrl('unambiguous'),
},
schema: [],
},

create: function (context) {
Expand Down
5 changes: 0 additions & 5 deletions tests/src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ ruleTester.run('default', rule, {
errors: [{ message: 'No default export found in imported module "./named-exports".'
, type: 'ImportDefaultSpecifier'}]}),

test({
code: "import Foo from './jsx/FooES7.js';",
errors: ["Parse errors in imported module './jsx/FooES7.js': Unexpected token = (6:16)"],
}),

// es7 export syntax
test({
code: 'export baz from "./named-exports"',
Expand Down
2 changes: 0 additions & 2 deletions tests/src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ ruleTester.run('export', rule, {
test({ code: 'export var foo = "foo", bar = "bar";' }),
test({ code: 'export var { foo, bar } = object;' }),
test({ code: 'export var [ foo, bar ] = array;' }),
test({ code: 'export var { foo, bar } = object;' }),
test({ code: 'export var [ foo, bar ] = array;' }),
test({ code: 'let foo; export { foo, foo as bar }' }),
test({ code: 'let bar; export { bar }; export * from "./export-all"' }),
test({ code: 'export * from "./export-all"' }),
Expand Down
1 change: 0 additions & 1 deletion tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ ruleTester.run('named', rule, {

test({
code: 'import { a } from "./re-export-names"',
options: [2, 'es6-only'],
errors: [error('a', './re-export-names')],
}),

Expand Down
10 changes: 0 additions & 10 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,6 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
} ],
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `var foo = require('foo-module');\nvar something = 123;`,
output: `var foo = require('foo-module');\n\nvar something = 123;`,
errors: [ {
line: 1,
column: 1,
message: REQUIRE_ERROR_MESSAGE,
} ],
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
},
{
code: `import foo from 'foo';\nvar a = 123;\n\nimport { bar } from './bar-lib';\nvar b=456;`,
output: `import foo from 'foo';\n\nvar a = 123;\n\nimport { bar } from './bar-lib';\n\nvar b=456;`,
Expand Down
23 changes: 11 additions & 12 deletions tests/src/rules/no-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
// imports
{ code: 'import "x";', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
{ code: 'import x from "x"', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
{ code: 'import x from "x"', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
{ code: 'import { x } from "x"', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },

// exports
Expand All @@ -30,15 +29,15 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
},

// allowed requires
{ code: 'function a() { var x = require("y"); }' }, // nested requires allowed
{ code: 'var a = c && require("b")' }, // conditional requires allowed
{ code: 'require.resolve("help")' }, // methods of require are allowed
{ code: 'require.ensure([])' }, // webpack specific require.ensure is allowed
{ code: 'require([], function(a, b, c) {})' }, // AMD require is allowed
{ code: "var bar = require('./bar', true);" },
{ code: "var bar = proxyquire('./bar');" },
{ code: "var bar = require('./ba' + 'r');" },
{ code: 'var zero = require(0);' },
'function a() { var x = require("y"); }', // nested requires allowed
'var a = c && require("b")', // conditional requires allowed
'require.resolve("help")', // methods of require are allowed
'require.ensure([])', // webpack specific require.ensure is allowed
'require([], function(a, b, c) {})', // AMD require is allowed
"var bar = require('./bar', true);",
"var bar = proxyquire('./bar');",
"var bar = require('./ba' + 'r');",
'var zero = require(0);',
{ code: 'require("x")', options: [{ allowRequire: true }] },

// commonJS doesn't care how the path is built. You can use a function to
Expand All @@ -61,8 +60,8 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
{ code: 'if (typeof window !== "undefined") require("x")', options: [{ allowRequire: false }] },
{ code: 'if (typeof window !== "undefined") { require("x") }', options: [{ allowRequire: true }] },
{ code: 'if (typeof window !== "undefined") { require("x") }', options: [{ allowRequire: false }] },
{ code: 'try { require("x") } catch (error) {}' },

'try { require("x") } catch (error) {}',
],

invalid: [
Expand Down
9 changes: 0 additions & 9 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ ruleTester.run('no-extraneous-dependencies', rule, {
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({ code: 'require(6)' }),
test({
code: 'import "doctrine"',
Expand Down Expand Up @@ -101,10 +96,6 @@ ruleTester.run('no-extraneous-dependencies', rule, {
code: 'import leftpad from "left-pad";',
options: [{packageDir: [packageDirMonoRepoRoot, packageDirMonoRepoWithNested]}],
}),
test({
code: 'import leftpad from "left-pad";',
options: [{packageDir: [packageDirMonoRepoWithNested, packageDirMonoRepoRoot]}],
}),
test({
code: 'import rightpad from "right-pad";',
options: [{packageDir: [packageDirMonoRepoRoot, packageDirMonoRepoWithNested]}],
Expand Down
1 change: 0 additions & 1 deletion tests/src/rules/no-unassigned-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ruleTester.run('no-unassigned-import', rule, {
test({ code: 'const {foo} = require("lodash")'}),
test({ code: 'const {foo: bar} = require("lodash")'}),
test({ code: 'const [a, b] = require("lodash")'}),
test({ code: 'const _ = require("lodash")'}),
test({ code: 'const _ = require("./")'}),
test({ code: 'foo(require("lodash"))'}),
test({ code: 'require("lodash").foo'}),
Expand Down

0 comments on commit d296ecf

Please sign in to comment.