[eslint] use prettier for all the things

This commit is contained in:
spalger 2019-12-12 09:16:24 -07:00 committed by spalger
parent e78689e61e
commit a3553c924d
5 changed files with 65 additions and 102 deletions

View file

@ -197,46 +197,6 @@ module.exports = {
},
},
/**
* Prettier
*/
{
files: [
'.eslintrc.js',
'packages/kbn-utility-types/**/*',
'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/legacy/plugins/apm/**/*',
'x-pack/legacy/plugins/canvas/**/*',
'**/*.{ts,tsx}',
'src/legacy/core_plugins/metrics/**/*.js',
],
plugins: ['prettier'],
rules: Object.assign(
{
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
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

View file

@ -5,7 +5,11 @@ module.exports = {
'./jest.js',
'./react.js',
],
plugins: ['@kbn/eslint-plugin-eslint'],
plugins: [
'@kbn/eslint-plugin-eslint',
'prettier',
],
parserOptions: {
ecmaVersion: 2018
@ -15,33 +19,44 @@ module.exports = {
es6: true,
},
rules: {
'@kbn/eslint/module_migration': [
'error',
[
rules: Object.assign(
{
'prettier/prettier': [
'error',
{
from: 'expect.js',
to: '@kbn/expect',
},
{
from: 'mkdirp',
to: false,
disallowedMessage: `Don't use 'mkdirp', use the new { recursive: true } option of Fs.mkdir instead`
},
{
from: '@kbn/elastic-idx',
to: false,
disallowedMessage: `Don't use idx(), use optional chaining syntax instead https://ela.st/optchain`
},
{
from: 'x-pack',
toRelative: 'x-pack',
},
{
from: 'react-router',
to: 'react-router-dom',
endOfLine: 'auto',
},
],
],
}
'@kbn/eslint/module_migration': [
'error',
[
{
from: 'expect.js',
to: '@kbn/expect',
},
{
from: 'mkdirp',
to: false,
disallowedMessage: `Don't use 'mkdirp', use the new { recursive: true } option of Fs.mkdir instead`
},
{
from: '@kbn/elastic-idx',
to: false,
disallowedMessage: `Don't use idx(), use optional chaining syntax instead https://ela.st/optchain`
},
{
from: 'x-pack',
toRelative: 'x-pack',
},
{
from: 'react-router',
to: 'react-router-dom',
},
],
],
},
require('eslint-config-prettier').rules,
require('eslint-config-prettier/react').rules
)
};

View file

@ -41,18 +41,12 @@ module.exports = {
rules: {
'block-scoped-var': 'error',
camelcase: [ 'error', { properties: 'never', allow: ['^UNSAFE_'] } ],
'comma-dangle': 'off',
'comma-spacing': ['error', { before: false, after: true }],
'comma-style': [ 'error', 'last' ],
'consistent-return': 'off',
curly: [ 'error', 'multi-line' ],
'dot-location': [ 'error', 'property' ],
'dot-notation': [ 'error', { allowKeywords: true } ],
eqeqeq: [ 'error', 'allow-null' ],
'guard-for-in': 'error',
indent: [ 'error', 2, { SwitchCase: 1 } ],
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
'max-len': [ 'error', 140, 2, { ignoreComments: true, ignoreUrls: true } ],
'new-cap': [ 'error', { capIsNewExceptions: [ 'Private' ] } ],
'no-bitwise': 'off',
'no-caller': 'error',
@ -62,13 +56,10 @@ module.exports = {
'no-empty': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-parens': 'off',
'no-extra-semi': [ 'error' ],
'no-global-assign': 'error',
'no-irregular-whitespace': 'error',
'no-iterator': 'error',
'no-loop-func': 'error',
'no-multi-spaces': 'off',
'no-multi-str': 'off',
'no-nested-ternary': 'error',
'no-new': 'off',
@ -82,7 +73,6 @@ module.exports = {
'no-script-url': 'error',
'no-sequences': 'error',
'no-shadow': 'off',
'no-trailing-spaces': 'error',
'no-undef': 'error',
'no-underscore-dangle': 'off',
'no-unsanitized/method': 'error',
@ -94,23 +84,11 @@ module.exports = {
'no-with': 'error',
'one-var': [ 'error', 'never' ],
'prefer-const': 'error',
quotes: [ 'error', 'single', { allowTemplateLiterals: true } ],
'semi-spacing': [ 'error', { before: false, after: true } ],
semi: [ 'error', 'always' ],
'space-before-blocks': [ 'error', 'always' ],
'space-before-function-paren': [ 'error', { anonymous: 'always', named: 'never' } ],
'space-in-parens': [ 'error', 'never' ],
'space-infix-ops': [ 'error', { int32Hint: false } ],
'space-unary-ops': [ 'error' ],
strict: [ 'error', 'never' ],
'valid-typeof': 'error',
'wrap-iife': [ 'error', 'outside' ],
'eol-last': ['error', 'always'],
yoda: 'off',
'object-curly-spacing': 'off', // overridden with babel/object-curly-spacing
'babel/object-curly-spacing': [ 'error', 'always' ],
'mocha/handle-done-callback': 'error',
'mocha/no-exclusive-tests': 'error',

View file

@ -97,21 +97,30 @@ module.exports = function({ name }) {
enforceNewFolder: true,
installDependencies: false,
gitInit: true,
post({ log }) {
return execa('yarn', ['kbn', 'bootstrap'], {
async post({ log }) {
await execa('yarn', ['kbn', 'bootstrap'], {
cwd: KBN_DIR,
stdio: 'inherit',
}).then(() => {
const dir = relative(process.cwd(), resolve(KBN_DIR, 'plugins', snakeCase(name)));
log.success(chalk`🎉
Your plugin has been created in {bold ${dir}}. Move into that directory to run it:
{bold cd "${dir}"}
{bold yarn start}
`);
});
const dir = relative(process.cwd(), resolve(KBN_DIR, 'plugins', snakeCase(name)));
try {
await execa('yarn', ['lint', '--fix'], {
cwd: dir,
all: true,
});
} catch (error) {
throw new Error(`Failure when running prettier on the generated output: ${error.all}`);
}
log.success(chalk`🎉
Your plugin has been created in {bold ${dir}}. Move into that directory to run it:
{bold cd "${dir}"}
{bold yarn start}
`);
},
};
};

View file

@ -41,7 +41,8 @@ export default function (kibana) {
},
<%_ if (generateApi || generateApp) { -%>
init(server, options) { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-unused-vars
init(server, options) {
<%_ if (generateApp) { -%>
const xpackMainPlugin = server.plugins.xpack_main;
if (xpackMainPlugin) {