From f00b516cd7ad3037039c98e7f1e80977f25d5d51 Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Fri, 7 Jun 2019 15:56:46 +0100 Subject: [PATCH] Update eslint config - Move to manageble private package - Ensure '.vue' rules are used via override - Add support for TypeScript - Update AP config to install correctly --- .eslintrc.js | 11 ++- azure-pipelines.yml | 3 + docs/.vuepress/.eslintrc.js | 21 ------ package.json | 4 +- tools/eslint-config/javascript.js | 13 ++++ tools/eslint-config/overrides/typescript.js | 81 +++++++++++++++++++++ tools/eslint-config/overrides/vue.js | 18 +++++ tools/eslint-config/package.json | 16 ++++ 8 files changed, 137 insertions(+), 30 deletions(-) delete mode 100644 docs/.vuepress/.eslintrc.js create mode 100644 tools/eslint-config/javascript.js create mode 100644 tools/eslint-config/overrides/typescript.js create mode 100644 tools/eslint-config/overrides/vue.js create mode 100644 tools/eslint-config/package.json diff --git a/.eslintrc.js b/.eslintrc.js index 5cc8274..824ff08 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,13 +1,12 @@ "use strict"; +const ts = require( "eslint-config-pegjs/overrides/typescript" )( __dirname ); +const vue = require( "eslint-config-pegjs/overrides/vue" ); + module.exports = { - "extends": "futagozaryuu/node-v6", + "extends": "pegjs", + "overrides": [ ts, vue ], "root": true, - "rules": { - - "no-eval": 0, - - }, }; diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e5c023b..cc14c7c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,9 @@ variables: jobs: - template: eslint.yml@apt + parameters: + install_scope: 'yarn' + job_script: 'yarn lint' - template: node-test.yml@apt parameters: diff --git a/docs/.vuepress/.eslintrc.js b/docs/.vuepress/.eslintrc.js deleted file mode 100644 index 585b054..0000000 --- a/docs/.vuepress/.eslintrc.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; - -module.exports = { - - "extends": "plugin:vue/recommended", - - "parserOptions": { - - // plugin:vue/recommended set's this to "module" for some reason... - "sourceType": "script" - - }, - - "rules": { - - "vue/html-indent": [ "error", 4 ], - "vue/singleline-html-element-content-newline": 0, - - }, - -}; diff --git a/package.json b/package.json index dd4a9ab..635868f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test" ], "scripts": { - "lint": "eslint --ext .js,.vue . docs/.vuepress", + "lint": "eslint --ext .js,.ts,.vue . docs/.vuepress", "spec": "mocha --reporter progress", "benchmark": "node tools/benchmark", "build-docs": "vuepress build docs", @@ -24,8 +24,6 @@ "dependencies": { "codecov": "3.3.0", "eslint": "5.16.0", - "eslint-config-futagozaryuu": "5.8.0", - "eslint-plugin-vue": "5.2.2", "mocha": "6.1.3", "mocha-junit-reporter": "1.22.0", "mocha-multi-reporters": "1.1.7", diff --git a/tools/eslint-config/javascript.js b/tools/eslint-config/javascript.js new file mode 100644 index 0000000..8685fd1 --- /dev/null +++ b/tools/eslint-config/javascript.js @@ -0,0 +1,13 @@ +"use strict"; + +module.exports = { + + "extends": "futagozaryuu/node-v6", + "rules": { + + "no-duplicate-imports": [ "error", { "includeExports": false } ], + "no-eval": 0, + + }, + +}; diff --git a/tools/eslint-config/overrides/typescript.js b/tools/eslint-config/overrides/typescript.js new file mode 100644 index 0000000..8aacea2 --- /dev/null +++ b/tools/eslint-config/overrides/typescript.js @@ -0,0 +1,81 @@ +"use strict"; + +const path = require( "path" ); + +const config = { + ...require( "eslint-config-futagozaryuu/stylistic-issues" ).rules, + ...require( "eslint-config-futagozaryuu/variables" ).rules, + ...require( "eslint-config-futagozaryuu/es2015" ).rules, +}; + +function ts( cwd ) { + + const ts = require( "@typescript-eslint/eslint-plugin/dist/configs/base.json" ); + ts.files = [ "*.ts" ]; + ts.parserOptions = { + + "project": path.join( cwd, "tsconfig.json" ), + "sourceType": "module", + + }; + ts.rules = { + + ...require( "@typescript-eslint/eslint-plugin/dist/configs/recommended.json" ).rules, + ...require( "@typescript-eslint/eslint-plugin/dist/configs/eslint-recommended" ).default.overrides[ 0 ].rules, + + "strict": "off", + "node/no-unsupported-features/es-syntax": "off", + + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/camelcase": "off", + "@typescript-eslint/explicit-member-accessibility": "off", + "@typescript-eslint/indent": config.indent, + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/member-delimiter-style": [ "error", { + "multiline": { + "delimiter": "semi", + "requireLast": true, + }, + "singleline": { + "delimiter": "semi", + "requireLast": true, + }, + } ], + "@typescript-eslint/member-naming": [ "warn", { + "private": "^_", + } ], + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/no-array-constructor": config[ "no-array-constructor" ], + "@typescript-eslint/no-empty-interface": "warn", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-extraneous-class": [ "error", { + "constructorOnly": true, + "allowEmpty": false, + "staticOnly": false, + } ], + "@typescript-eslint/no-for-in-array": "error", + "@typescript-eslint/no-inferrable-types": "off", + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-type-alias": "off", + "@typescript-eslint/no-unnecessary-type-assertion": "error", + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "off", + "no-use-before-define": "off", + "@typescript-eslint/no-use-before-define": config[ "no-use-before-define" ], + "no-useless-constructor": "off", + "@typescript-eslint/no-useless-constructor": config[ "no-useless-constructor" ], + "@typescript-eslint/promise-function-async": "off", + "@typescript-eslint/restrict-plus-operands": "error", + "@typescript-eslint/type-annotation-spacing": "error", + "@typescript-eslint/prefer-interface": "off", + "@typescript-eslint/explicit-function-return-type": [ "error", { + allowExpressions: true, + } ], + + }; + + return ts; + +} + +module.exports = ts; diff --git a/tools/eslint-config/overrides/vue.js b/tools/eslint-config/overrides/vue.js new file mode 100644 index 0000000..1fa866a --- /dev/null +++ b/tools/eslint-config/overrides/vue.js @@ -0,0 +1,18 @@ +"use strict"; + +const vue = require( "eslint-plugin-vue/lib/configs/base" ); + +vue.files = [ "*.vue" ]; + +Object.assign( vue.rules, { + + ...require( "eslint-plugin-vue/lib/configs/essential" ).rules, + ...require( "eslint-plugin-vue/lib/configs/strongly-recommended" ).rules, + ...require( "eslint-plugin-vue/lib/configs/recommended" ).rules, + + "vue/html-indent": [ "error", 4 ], + "vue/singleline-html-element-content-newline": 0, + +} ); + +module.exports = vue; diff --git a/tools/eslint-config/package.json b/tools/eslint-config/package.json new file mode 100644 index 0000000..da2bfa8 --- /dev/null +++ b/tools/eslint-config/package.json @@ -0,0 +1,16 @@ +{ + "name": "eslint-config-pegjs", + "version": "2.3.0", + "private": true, + "main": "javascript.js", + "dependencies": { + "@typescript-eslint/eslint-plugin": "1.9.1-alpha.26", + "@typescript-eslint/parser": "1.9.1-alpha.26", + "eslint-config-futagozaryuu": "5.8.0", + "eslint-plugin-vue": "5.2.2", + "typescript": "3.5.1" + }, + "engines": { + "node": ">= 6" + } +}