From 0b40a0db0fd75322023d7617e0659038c270946b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 24 Sep 2020 09:35:18 +0200 Subject: [PATCH] improve eslint config --- .eslintignore | 4 -- .eslintrc.js | 99 +++++++++++++++------------ package.json | 2 +- packages/core/src/Editor.ts | 1 + packages/core/src/EventEmitter.ts | 26 +++---- packages/core/src/ExtensionManager.ts | 7 +- shims/vue.d.ts | 7 +- tests/cypress/plugins/index.js | 1 + 8 files changed, 80 insertions(+), 67 deletions(-) delete mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 7d758b7b..00000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -dist/** -tests/** -**/*.css -**/*.json diff --git a/.eslintrc.js b/.eslintrc.js index fca7f571..f8f8b40b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,54 +1,67 @@ module.exports = { - plugins: ['html', 'cypress', '@typescript-eslint'], - parserOptions: { parser: '@typescript-eslint/parser', sourceType: 'module', }, - env: { es6: true, node: true, - 'cypress/globals': true, }, - - globals: { - document: false, - window: false, - }, - - extends: [ - 'plugin:vue/strongly-recommended', - 'airbnb-base', - ], - - rules: { - semi: ['error', 'never'], - 'import/extensions': 'off', - 'import/no-extraneous-dependencies': 'off', - 'import/no-unresolved': 'off', - 'import/no-dynamic-require': 'off', - 'arrow-parens': ['error', 'as-needed'], - 'padded-blocks': 'off', - 'class-methods-use-this': 'off', - 'global-require': 'off', - 'func-names': ['error', 'never'], - 'arrow-body-style': 'off', - 'max-len': 'off', - 'vue/this-in-template': ['error', 'never'], - 'vue/max-attributes-per-line': ['error', { - singleline: 3, - multiline: { - max: 1, - allowFirstLine: false, + overrides: [ + { + files: [ + './**/*.ts', + './**/*.js', + './**/*.vue', + ], + excludedFiles: [ + 'dist/**', + ], + plugins: [ + 'html', + 'cypress', + '@typescript-eslint', + ], + env: { + 'cypress/globals': true, }, - }], - 'no-param-reassign': 'off', - 'import/prefer-default-export': 'off', - 'consistent-return': 'off', - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': ['error'], - 'no-use-before-define': 'off', - '@typescript-eslint/no-use-before-define': ['error'], - }, + globals: { + document: false, + window: false, + }, + extends: [ + 'plugin:vue/strongly-recommended', + 'airbnb-base', + ], + rules: { + semi: ['error', 'never'], + 'import/extensions': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/no-unresolved': 'off', + 'import/no-dynamic-require': 'off', + 'arrow-parens': ['error', 'as-needed'], + 'padded-blocks': 'off', + 'class-methods-use-this': 'off', + 'global-require': 'off', + 'func-names': ['error', 'never'], + 'arrow-body-style': 'off', + 'max-len': 'off', + 'vue/this-in-template': ['error', 'never'], + 'vue/max-attributes-per-line': ['error', { + singleline: 3, + multiline: { + max: 1, + allowFirstLine: false, + }, + }], + 'no-param-reassign': 'off', + 'import/prefer-default-export': 'off', + 'consistent-return': 'off', + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': ['error'], + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': ['error'], + }, + }, + ], } diff --git a/package.json b/package.json index 67db0426..40e28492 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build:docs": "yarn --cwd ./docs build", "build:packages": "yarn clean:packages && lerna exec --parallel -- microbundle --compress", "clean:packages": "rm -rf ./packages/*/dist", - "lint": "eslint --quiet --no-error-on-unmatched-pattern --ext .js,.jsx,.ts,.vue ./docs ./packages", + "lint": "eslint --quiet --no-error-on-unmatched-pattern ./", "test:open": "cypress open --project tests", "test": "cypress run --project tests", "reset": "yarn clean:packages && rm -rf ./**/.cache && rm -rf ./**/node_modules && rm -rf ./yarn.lock && yarn install" diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 92618588..2194a5d6 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -131,6 +131,7 @@ export class Editor extends EventEmitter { * * @param name The name of the command */ + // eslint-disable-next-line private __get(name: string) { return this.commandManager.runSingleCommand(name) } diff --git a/packages/core/src/EventEmitter.ts b/packages/core/src/EventEmitter.ts index 7d83d475..fa5d7f2a 100644 --- a/packages/core/src/EventEmitter.ts +++ b/packages/core/src/EventEmitter.ts @@ -1,19 +1,19 @@ export default class EventEmitter { - _callbacks: { [key: string]: Function[] } = {} + private callbacks: { [key: string]: Function[] } = {} - on(event: string, fn: Function) { - if (!this._callbacks[event]) { - this._callbacks[event] = [] + public on(event: string, fn: Function) { + if (!this.callbacks[event]) { + this.callbacks[event] = [] } - this._callbacks[event].push(fn) + this.callbacks[event].push(fn) return this } - emit(event: string, ...args: any) { - const callbacks = this._callbacks[event] + protected emit(event: string, ...args: any) { + const callbacks = this.callbacks[event] if (callbacks) { callbacks.forEach(callback => callback.apply(this, args)) @@ -22,21 +22,21 @@ export default class EventEmitter { return this } - off(event: string, fn?: Function) { - const callbacks = this._callbacks[event] + public off(event: string, fn?: Function) { + const callbacks = this.callbacks[event] if (callbacks) { if (fn) { - this._callbacks[event] = callbacks.filter(callback => callback !== fn) + this.callbacks[event] = callbacks.filter(callback => callback !== fn) } else { - delete this._callbacks[event] + delete this.callbacks[event] } } return this } - removeAllListeners() { - this._callbacks = {} + protected removeAllListeners() { + this.callbacks = {} } } diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 5309e75a..d0c8b67f 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -2,12 +2,13 @@ import deepmerge from 'deepmerge' import collect from 'collect.js' import { Plugin } from 'prosemirror-state' import { keymap } from 'prosemirror-keymap' -import { Schema, Node as ProsemirrorNode } from 'prosemirror-model' +import { Schema } from 'prosemirror-model' +// import { Schema, Node as ProsemirrorNode } from 'prosemirror-model' import { inputRules } from 'prosemirror-inputrules' -import { EditorView, Decoration } from 'prosemirror-view' +// import { EditorView, Decoration } from 'prosemirror-view' import { Editor } from './Editor' -import capitalize from './utils/capitalize' +// import capitalize from './utils/capitalize' import { Extensions } from './types' import getTopNodeFromExtensions from './utils/getTopNodeFromExtensions' import getNodesFromExtensions from './utils/getNodesFromExtensions' diff --git a/shims/vue.d.ts b/shims/vue.d.ts index c360906b..5596f90e 100644 --- a/shims/vue.d.ts +++ b/shims/vue.d.ts @@ -1,4 +1,5 @@ -declare module "*.vue" { - import Vue from "vue" +declare module '*.vue' { + import Vue from 'vue' + export default Vue -} \ No newline at end of file +} diff --git a/tests/cypress/plugins/index.js b/tests/cypress/plugins/index.js index fd170fba..94620a2c 100644 --- a/tests/cypress/plugins/index.js +++ b/tests/cypress/plugins/index.js @@ -11,6 +11,7 @@ // This function is called when a project is opened or re-opened (e.g. due to // the project's config changing) +// eslint-disable-next-line module.exports = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config