* chore(NA): remove tslint dependencies, configs and enable eslint typescript parser. * fix(NA): apply recommend eslint typescript rule.s * chore(NA): upgrade eslint package versions. * chore(NA): split javascript eslint config in an override section. * chore(NA): split all eslint configs with overrides. * chore(NA): remove missing console.log. * chore(NA): change eslint splits and overrides order. * chore(NA): replace tslint disable comments with eslint ones. * chore(NA): solve eslint typescript errors for elastic/kibana-custom/no-default-export * chore(NA): fixed multiple eslint typescript rule failures. * chore(NA): add tarfet folder to the eslint ignore. * chore(NA): apply prettier rule to ts type file. * chore(NA): remove last mentions to tslint * chore(NA): add old defined rules * chore(NA): missing port rules website * chore(na): ordered rules * chore(NA): solved eslint typescript problems. * chore(NA): fix spaced comment problems. * chore(NA): fix some more eslint typescript rules: import/order no-empty-interface * chore(NA): fix last rules and comment out what are the ones still failing. * chore(NA): comment out camelcase rule. * chore(NA): regenerate kbn pm dist. * chore(NA): updated snapshots. * chore(NA): updated snapshots. * chore(NA): disabled sort-keys rule. * chore(NA): remove rule prefer-arrow/prefer-arrow-functions. * chore(NA): fix for @typescript-eslint/no-var-requires rule. * chore(NA): fixes for @typescript-eslint/camelcase rule. * chore(NA): fix typo on eslint config kibana typescript. Co-Authored-By: mistic <tiagoffcc@hotmail.com> * chore(NA): remove legacy note after the intellij upgrade to 2019.1 * fix(NA): import order plugin. * chore(NA): fix ts ignore positions after auto fix. * fix(NA): performance issue with typescript eslint. * refact(NA): eslint configs organization. * chore(NA): apply resticted paths to ts files too. * chore(NA): split comment from eslint ignore.
516 lines
14 KiB
JavaScript
516 lines
14 KiB
JavaScript
const { readdirSync } = require('fs');
|
|
const { resolve } = require('path');
|
|
|
|
const APACHE_2_0_LICENSE_HEADER = `
|
|
/*
|
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
* license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright
|
|
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
* not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
* KIND, either express or implied. See the License for the
|
|
* specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
`;
|
|
|
|
const ELASTIC_LICENSE_HEADER = `
|
|
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
`;
|
|
|
|
module.exports = {
|
|
extends: ['@elastic/eslint-config-kibana'],
|
|
|
|
overrides: [
|
|
/**
|
|
* Prettier
|
|
*/
|
|
{
|
|
files: [
|
|
'.eslintrc.js',
|
|
'packages/kbn-eslint-plugin-eslint/**/*',
|
|
'packages/kbn-config-schema/**/*',
|
|
'packages/kbn-pm/**/*',
|
|
'packages/kbn-es/**/*',
|
|
'packages/elastic-datemath/**/*',
|
|
'packages/kbn-i18n/**/*',
|
|
'packages/kbn-dev-utils/**/*',
|
|
'packages/kbn-plugin-helpers/**/*',
|
|
'packages/kbn-plugin-generator/**/*',
|
|
'packages/kbn-test-subj-selector/**/*',
|
|
'packages/kbn-test/**/*',
|
|
'packages/kbn-eslint-import-resolver-kibana/**/*',
|
|
'src/legacy/server/saved_objects/**/*',
|
|
'x-pack/plugins/apm/**/*',
|
|
'x-pack/plugins/canvas/**/*',
|
|
'**/*.{ts,tsx}',
|
|
],
|
|
plugins: ['prettier'],
|
|
rules: Object.assign(
|
|
{
|
|
'prettier/prettier': ['error'],
|
|
},
|
|
require('eslint-config-prettier').rules,
|
|
require('eslint-config-prettier/react').rules
|
|
),
|
|
},
|
|
|
|
/**
|
|
* Files that require Apache 2.0 headers, settings
|
|
* are overridden below for files that require Elastic
|
|
* Licence headers
|
|
*/
|
|
{
|
|
files: ['**/*.{js,ts,tsx}'],
|
|
rules: {
|
|
'@kbn/eslint/require-license-header': [
|
|
'error',
|
|
{
|
|
license: APACHE_2_0_LICENSE_HEADER,
|
|
},
|
|
],
|
|
'@kbn/eslint/disallow-license-headers': [
|
|
'error',
|
|
{
|
|
licenses: [ELASTIC_LICENSE_HEADER],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that require Elastic license headers instead of Apache 2.0 header
|
|
*/
|
|
{
|
|
files: ['x-pack/**/*.{js,ts,tsx}'],
|
|
rules: {
|
|
'@kbn/eslint/require-license-header': [
|
|
'error',
|
|
{
|
|
license: ELASTIC_LICENSE_HEADER,
|
|
},
|
|
],
|
|
'@kbn/eslint/disallow-license-headers': [
|
|
'error',
|
|
{
|
|
licenses: [APACHE_2_0_LICENSE_HEADER],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Restricted paths
|
|
*/
|
|
{
|
|
files: ['**/*.{js,ts,tsx}'],
|
|
rules: {
|
|
'@kbn/eslint/no-restricted-paths': [
|
|
'error',
|
|
{
|
|
basePath: __dirname,
|
|
zones: [
|
|
{
|
|
target: [
|
|
'src/legacy/**/*',
|
|
'x-pack/**/*',
|
|
'!x-pack/**/*.test.*',
|
|
'src/plugins/**/(public|server)/**/*',
|
|
'src/core/(public|server)/**/*',
|
|
],
|
|
from: [
|
|
'src/core/public/**/*',
|
|
'!src/core/public/index*',
|
|
'!src/core/public/utils/**/*',
|
|
|
|
'src/core/server/**/*',
|
|
'!src/core/server/index*',
|
|
|
|
'src/plugins/**/public/**/*',
|
|
'!src/plugins/**/public/index*',
|
|
|
|
'src/plugins/**/server/**/*',
|
|
'!src/plugins/**/server/index*',
|
|
],
|
|
allowSameFolder: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Allow default exports
|
|
*/
|
|
{
|
|
files: ['x-pack/test/functional/apps/**/*.js', 'x-pack/plugins/apm/**/*.js'],
|
|
rules: {
|
|
'import/no-default-export': 'off',
|
|
'import/no-named-as-default': 'off',
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that are allowed to import webpack-specific stuff
|
|
*/
|
|
{
|
|
files: [
|
|
'**/public/**/*.js',
|
|
'**/webpackShims/**/*.js',
|
|
'packages/kbn-ui-framework/doc_site/src/**/*.js',
|
|
'src/fixtures/**/*.js', // TODO: this directory needs to be more obviously "public" (or go away)
|
|
],
|
|
settings: {
|
|
// instructs import/no-extraneous-dependencies to treat modules
|
|
// in plugins/ or ui/ namespace as "core modules" so they don't
|
|
// trigger failures for not being listed in package.json
|
|
'import/core-modules': ['plugins', 'legacy/ui', 'uiExports'],
|
|
|
|
'import/resolver': {
|
|
'@kbn/eslint-import-resolver-kibana': {
|
|
forceNode: false,
|
|
rootPackageName: 'kibana',
|
|
kibanaPath: '.',
|
|
pluginMap: readdirSync(resolve(__dirname, 'x-pack/plugins')).reduce((acc, name) => {
|
|
if (!name.startsWith('_')) {
|
|
acc[name] = `x-pack/plugins/${name}`;
|
|
}
|
|
return acc;
|
|
}, {}),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that ARE NOT allowed to use devDependencies
|
|
*/
|
|
{
|
|
files: [
|
|
'packages/kbn-ui-framework/**/*.js',
|
|
'x-pack/**/*.js',
|
|
'packages/kbn-interpreter/**/*.js',
|
|
],
|
|
rules: {
|
|
'import/no-extraneous-dependencies': [
|
|
'error',
|
|
{
|
|
devDependencies: false,
|
|
peerDependencies: true,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that ARE allowed to use devDependencies
|
|
*/
|
|
{
|
|
files: [
|
|
'packages/kbn-ui-framework/**/*.test.js',
|
|
'packages/kbn-ui-framework/doc_site/**/*.js',
|
|
'packages/kbn-ui-framework/generator-kui/**/*.js',
|
|
'packages/kbn-ui-framework/Gruntfile.js',
|
|
'packages/kbn-es/src/**/*.js',
|
|
'packages/kbn-interpreter/tasks/**/*.js',
|
|
'packages/kbn-interpreter/src/plugin/**/*.js',
|
|
'x-pack/{dev-tools,tasks,scripts,test,build_chromium}/**/*.js',
|
|
'x-pack/**/{__tests__,__test__,__jest__,__fixtures__,__mocks__}/**/*.js',
|
|
'x-pack/**/*.test.js',
|
|
'x-pack/test_utils/**/*',
|
|
'x-pack/gulpfile.js',
|
|
'x-pack/plugins/apm/public/utils/testHelpers.js',
|
|
],
|
|
rules: {
|
|
'import/no-extraneous-dependencies': [
|
|
'error',
|
|
{
|
|
devDependencies: true,
|
|
peerDependencies: true,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that run BEFORE node version check
|
|
*/
|
|
{
|
|
files: ['scripts/**/*.js', 'src/setup_node_env/**/*.js'],
|
|
rules: {
|
|
'import/no-commonjs': 'off',
|
|
'prefer-object-spread/prefer-object-spread': 'off',
|
|
'no-var': 'off',
|
|
'prefer-const': 'off',
|
|
'prefer-destructuring': 'off',
|
|
'no-restricted-syntax': [
|
|
'error',
|
|
'ImportDeclaration',
|
|
'ExportNamedDeclaration',
|
|
'ExportDefaultDeclaration',
|
|
'ExportAllDeclaration',
|
|
'ArrowFunctionExpression',
|
|
'AwaitExpression',
|
|
'ClassDeclaration',
|
|
'RestElement',
|
|
'SpreadElement',
|
|
'YieldExpression',
|
|
'VariableDeclaration[kind="const"]',
|
|
'VariableDeclaration[kind="let"]',
|
|
'VariableDeclarator[id.type="ArrayPattern"]',
|
|
'VariableDeclarator[id.type="ObjectPattern"]',
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that run in the browser with only node-level transpilation
|
|
*/
|
|
{
|
|
files: [
|
|
'test/functional/services/lib/web_element_wrapper/scroll_into_view_if_necessary.js',
|
|
'**/browser_exec_scripts/**/*.js',
|
|
],
|
|
rules: {
|
|
'prefer-object-spread/prefer-object-spread': 'off',
|
|
'no-var': 'off',
|
|
'prefer-const': 'off',
|
|
'prefer-destructuring': 'off',
|
|
'no-restricted-syntax': [
|
|
'error',
|
|
'ArrowFunctionExpression',
|
|
'AwaitExpression',
|
|
'ClassDeclaration',
|
|
'ImportDeclaration',
|
|
'RestElement',
|
|
'SpreadElement',
|
|
'YieldExpression',
|
|
'VariableDeclaration[kind="const"]',
|
|
'VariableDeclaration[kind="let"]',
|
|
'VariableDeclarator[id.type="ArrayPattern"]',
|
|
'VariableDeclarator[id.type="ObjectPattern"]',
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Files that run AFTER node version check
|
|
* and are not also transpiled with babel
|
|
*/
|
|
{
|
|
files: [
|
|
'.eslintrc.js',
|
|
'**/webpackShims/**/*.js',
|
|
'packages/kbn-plugin-generator/**/*.js',
|
|
'packages/kbn-plugin-helpers/**/*.js',
|
|
'packages/kbn-eslint-import-resolver-kibana/**/*.js',
|
|
'packages/kbn-eslint-plugin-eslint/**/*',
|
|
'x-pack/gulpfile.js',
|
|
'x-pack/dev-tools/mocha/setup_mocha.js',
|
|
'x-pack/scripts/*.js',
|
|
],
|
|
rules: {
|
|
'import/no-commonjs': 'off',
|
|
'prefer-object-spread/prefer-object-spread': 'off',
|
|
'no-restricted-syntax': [
|
|
'error',
|
|
'ImportDeclaration',
|
|
'ExportNamedDeclaration',
|
|
'ExportDefaultDeclaration',
|
|
'ExportAllDeclaration',
|
|
],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* APM overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/apm/**/*.js'],
|
|
rules: {
|
|
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
|
|
'no-console': ['warn', { allow: ['error'] }],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* GIS overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/maps/**/*.js'],
|
|
rules: {
|
|
'react/prefer-stateless-function': [0, { ignorePureComponents: false }],
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Graph overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/graph/**/*.js'],
|
|
globals: {
|
|
angular: true,
|
|
$: true,
|
|
},
|
|
rules: {
|
|
'block-scoped-var': 'off',
|
|
camelcase: 'off',
|
|
eqeqeq: 'off',
|
|
'guard-for-in': 'off',
|
|
'new-cap': 'off',
|
|
'no-loop-func': 'off',
|
|
'no-redeclare': 'off',
|
|
'no-shadow': 'off',
|
|
'no-unused-vars': 'off',
|
|
'one-var': 'off',
|
|
},
|
|
},
|
|
|
|
/**
|
|
* ML overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/ml/**/*.js'],
|
|
rules: {
|
|
'no-shadow': 'error',
|
|
},
|
|
},
|
|
|
|
/**
|
|
* disable jsx-a11y for kbn-ui-framework
|
|
*/
|
|
{
|
|
files: ['packages/kbn-ui-framework/**/*.js'],
|
|
rules: {
|
|
'jsx-a11y/click-events-have-key-events': 'off',
|
|
'jsx-a11y/anchor-has-content': 'off',
|
|
'jsx-a11y/tabindex-no-positive': 'off',
|
|
'jsx-a11y/label-has-associated-control': 'off',
|
|
'jsx-a11y/aria-role': 'off',
|
|
},
|
|
},
|
|
|
|
/**
|
|
* Monitoring overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/monitoring/**/*.js'],
|
|
rules: {
|
|
'block-spacing': ['error', 'always'],
|
|
curly: ['error', 'all'],
|
|
'no-unused-vars': ['error', { args: 'all', argsIgnorePattern: '^_' }],
|
|
'no-else-return': 'error',
|
|
},
|
|
},
|
|
{
|
|
files: ['x-pack/plugins/monitoring/public/**/*.js'],
|
|
env: { browser: true },
|
|
},
|
|
|
|
/**
|
|
* Canvas overrides
|
|
*/
|
|
{
|
|
files: ['x-pack/plugins/canvas/**/*.js'],
|
|
rules: {
|
|
radix: 'error',
|
|
curly: ['error', 'all'],
|
|
|
|
// module importing
|
|
'import/order': [
|
|
'error',
|
|
{
|
|
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
|
},
|
|
],
|
|
'import/extensions': ['error', 'never', { json: 'always', less: 'always', svg: 'always' }],
|
|
|
|
// react
|
|
'react/no-did-mount-set-state': 'error',
|
|
'react/no-did-update-set-state': 'error',
|
|
'react/no-multi-comp': ['error', { ignoreStateless: true }],
|
|
'react/self-closing-comp': 'error',
|
|
'react/sort-comp': 'error',
|
|
'react/jsx-boolean-value': 'error',
|
|
'react/jsx-wrap-multilines': 'error',
|
|
'react/no-unescaped-entities': ['error', { forbid: ['>', '}'] }],
|
|
'react/forbid-elements': [
|
|
'error',
|
|
{
|
|
forbid: [
|
|
{
|
|
element: 'EuiConfirmModal',
|
|
message: 'Use <ConfirmModal> instead',
|
|
},
|
|
{
|
|
element: 'EuiPopover',
|
|
message: 'Use <Popover> instead',
|
|
},
|
|
{
|
|
element: 'EuiIconTip',
|
|
message: 'Use <TooltipIcon> instead',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
files: [
|
|
'x-pack/plugins/canvas/gulpfile.js',
|
|
'x-pack/plugins/canvas/scripts/*.js',
|
|
'x-pack/plugins/canvas/tasks/*.js',
|
|
'x-pack/plugins/canvas/tasks/**/*.js',
|
|
'x-pack/plugins/canvas/__tests__/**/*.js',
|
|
'x-pack/plugins/canvas/**/{__tests__,__test__,__jest__,__fixtures__,__mocks__}/**/*.js',
|
|
],
|
|
rules: {
|
|
'import/no-extraneous-dependencies': [
|
|
'error',
|
|
{
|
|
devDependencies: true,
|
|
peerDependencies: true,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
files: ['x-pack/plugins/canvas/canvas_plugin_src/**/*.js'],
|
|
globals: { canvas: true, $: true },
|
|
rules: {
|
|
'import/no-unresolved': [
|
|
'error',
|
|
{
|
|
ignore: ['!!raw-loader.+.svg$'],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
files: ['x-pack/plugins/canvas/public/**/*.js'],
|
|
env: {
|
|
browser: true,
|
|
},
|
|
},
|
|
{
|
|
files: ['x-pack/plugins/canvas/canvas_plugin_src/lib/flot-charts/**/*.js'],
|
|
env: {
|
|
jquery: true,
|
|
},
|
|
},
|
|
],
|
|
};
|