Skip to content

Commit

Permalink
[7.0] [eslint] merge custom rules into a single plugin (#33733) (#33759)
Browse files Browse the repository at this point in the history
Backports the following commits to 7.0:
 - [eslint] merge custom rules into a single plugin  (#33733)
  • Loading branch information
Spencer authored Mar 23, 2019
1 parent 2a65969 commit 56352b2
Show file tree
Hide file tree
Showing 41 changed files with 196 additions and 191 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bower_components
/src/core/lib/kbn_internal_native_observable
/packages/*/target
/packages/eslint-config-kibana
/packages/eslint-plugin-kibana-custom
/packages/kbn-es-query/src/kuery/ast/kuery.js
/packages/kbn-es-query/src/kuery/ast/legacy_kuery.js
/packages/kbn-pm/dist
Expand Down
17 changes: 8 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ELASTIC_LICENSE_HEADER = `

module.exports = {
extends: ['@elastic/eslint-config-kibana', '@elastic/eslint-config-kibana/jest'],
plugins: ['@kbn/eslint-plugin-eslint'],

settings: {
'import/resolver': {
Expand All @@ -55,7 +56,7 @@ module.exports = {
{
files: [
'.eslintrc.js',
'packages/eslint-plugin-kibana-custom/**/*',
'packages/kbn-eslint-plugin-eslint/**/*',
'packages/kbn-config-schema/**/*',
'packages/kbn-pm/**/*',
'packages/kbn-es/**/*',
Expand Down Expand Up @@ -86,7 +87,7 @@ module.exports = {
{
files: ['x-pack/test/functional/apps/**/*', 'x-pack/plugins/apm/**/*'],
rules: {
'kibana-custom/no-default-export': 'off',
'@kbn/eslint/no-default-export': 'off',
'import/no-named-as-default': 'off',
},
},
Expand Down Expand Up @@ -240,7 +241,7 @@ module.exports = {
'packages/kbn-plugin-generator/**/*',
'packages/kbn-plugin-helpers/**/*',
'packages/kbn-eslint-import-resolver-kibana/**/*',
'packages/kbn-eslint-plugin-license-header/**/*',
'packages/kbn-eslint-plugin-eslint/**/*',
'x-pack/gulpfile.js',
'x-pack/dev-tools/mocha/setup_mocha.js',
'x-pack/scripts/*',
Expand All @@ -265,15 +266,14 @@ module.exports = {
*/
{
files: ['**/*.js'],
plugins: ['@kbn/eslint-plugin-license-header'],
rules: {
'@kbn/license-header/require-license-header': [
'@kbn/eslint/require-license-header': [
'error',
{
license: APACHE_2_0_LICENSE_HEADER,
},
],
'@kbn/license-header/disallow-license-headers': [
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [ELASTIC_LICENSE_HEADER],
Expand All @@ -297,15 +297,14 @@ module.exports = {
*/
{
files: ['x-pack/**/*.js'],
plugins: ['@kbn/eslint-plugin-license-header'],
rules: {
'@kbn/license-header/require-license-header': [
'@kbn/eslint/require-license-header': [
'error',
{
license: ELASTIC_LICENSE_HEADER,
},
],
'@kbn/license-header/disallow-license-headers': [
'@kbn/eslint/disallow-license-headers': [
'error',
{
licenses: [APACHE_2_0_LICENSE_HEADER],
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,10 @@
"@babel/parser": "^7.1.0",
"@babel/types": "^7.0.0",
"@elastic/eslint-config-kibana": "0.15.0",
"@elastic/eslint-plugin-kibana-custom": "1.1.0",
"@elastic/makelogs": "^4.4.0",
"@kbn/es": "1.0.0",
"@kbn/eslint-import-resolver-kibana": "2.0.0",
"@kbn/eslint-plugin-license-header": "1.0.0",
"@kbn/eslint-plugin-eslint": "1.0.0",
"@kbn/plugin-generator": "1.0.0",
"@kbn/test": "1.0.0",
"@octokit/rest": "^15.10.0",
Expand Down
14 changes: 0 additions & 14 deletions packages/eslint-plugin-kibana-custom/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/eslint-plugin-kibana-custom/package.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
rules: {
'require-license-header': require('./rules/require_license_header'),
'disallow-license-headers': require('./rules/disallow_license_headers'),
'no-default-export': require('./rules/no_default_export'),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ exports.normalizeWhitespace = function normalizeWhitespace(string) {
return string.replace(/\s+/g, ' ');
};

exports.init = function (context, program, initStep) {
exports.init = function(context, program, initStep) {
try {
return initStep();
} catch (error) {
if (error.failedAssertion) {
context.report({
node: program,
message: error.message
message: error.message,
});
} else {
throw error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@kbn/eslint-plugin-license-header",
"name": "@kbn/eslint-plugin-eslint",
"version": "1.0.0",
"private": true,
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ const { RuleTester } = require('eslint');
const rule = require('../disallow_license_headers');
const dedent = require('dedent');

const RULE_NAME = '@kbn/license-header/disallow-license-headers';

const ruleTester = new RuleTester({
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2015
}
ecmaVersion: 2015,
},
});
ruleTester.run(RULE_NAME, rule, {

ruleTester.run('@kbn/eslint/disallow-license-headers', rule, {
valid: [
{
code: dedent`
Expand All @@ -38,11 +37,11 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
'// license'
]
}],
options: [
{
licenses: ['// license'],
},
],
},
{
code: dedent`
Expand All @@ -51,12 +50,12 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
'/* license */',
]
}],
}
options: [
{
licenses: ['/* license */'],
},
],
},
],

invalid: [
Expand All @@ -70,8 +69,8 @@ ruleTester.run(RULE_NAME, rule, {
errors: [
{
message: '"licenses" option is required',
}
]
},
],
},

// license cannot contain multiple block comments
Expand All @@ -80,16 +79,16 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
'/* one *//* two */'
]
}],
options: [
{
licenses: ['/* one *//* two */'],
},
],
errors: [
{
message: '"licenses[0]" option must only include a single comment',
}
]
},
],
},

// license cannot contain multiple line comments
Expand All @@ -98,16 +97,16 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
`// one\n// two`
]
}],
options: [
{
licenses: [`// one\n// two`],
},
],
errors: [
{
message: '"licenses[0]" option must only include a single comment',
}
]
},
],
},

// license cannot contain expressions
Expand All @@ -116,20 +115,22 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
'// old license',
dedent`
options: [
{
licenses: [
'// old license',
dedent`
/* license */
console.log('hello world');
`
]
}],
`,
],
},
],
errors: [
{
message: '"licenses[1]" option must only include a single comment',
}
]
},
],
},

// license is not a single comment
Expand All @@ -138,18 +139,16 @@ ruleTester.run(RULE_NAME, rule, {
console.log('foo')
`,

options: [{
licenses: [
'// old license',
'// older license',
`console.log('hello world');`
]
}],
options: [
{
licenses: ['// old license', '// older license', `console.log('hello world');`],
},
],
errors: [
{
message: '"licenses[2]" option must only include a single comment',
}
]
},
],
},
]
],
});
Loading

0 comments on commit 56352b2

Please sign in to comment.