From 22aeca5c3ad2a5f5775b7a6134b56236de00b217 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Mon, 19 Jun 2017 06:41:18 +0900 Subject: [PATCH] Fix: upgrade vue-eslint-parser (#34) * Fix: upgrade vue-eslint-parser - Make correct ASTs about self-closing elements (fixes #29) - Improve the integration with eslint-plugin-import (refs #21) * add comments to integration test --- .gitignore | 1 + .vscode/settings.json | 3 ++ package-lock.json | 4 +- package.json | 4 +- tests/.eslintrc.json | 5 +++ tests/integrations/eslint-plugin-import.js | 39 +++++++++++++++++++ .../eslint-plugin-import/.eslintrc.json | 22 +++++++++++ tests/integrations/eslint-plugin-import/a.vue | 10 +++++ tests/integrations/eslint-plugin-import/b.vue | 7 ++++ .../eslint-plugin-import/package.json | 15 +++++++ tests/lib/rules/no-invalid-template-root.js | 4 ++ tests/lib/rules/no-invalid-v-else-if.js | 4 ++ tests/lib/rules/no-invalid-v-else.js | 4 ++ 13 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 tests/.eslintrc.json create mode 100644 tests/integrations/eslint-plugin-import.js create mode 100644 tests/integrations/eslint-plugin-import/.eslintrc.json create mode 100644 tests/integrations/eslint-plugin-import/a.vue create mode 100644 tests/integrations/eslint-plugin-import/b.vue create mode 100644 tests/integrations/eslint-plugin-import/package.json diff --git a/.gitignore b/.gitignore index 0f23426ce..f5ee9df9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.nyc_output /coverage +/tests/integrations/*/node_modules /node_modules /test.* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..ce072c82c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.tabSize": 2 +} diff --git a/package-lock.json b/package-lock.json index 9bbf5b436..89fa33c39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1974,7 +1974,9 @@ "dev": true }, "vue-eslint-parser": { - "version": "github:mysticatea/vue-eslint-parser#1250373ccff349c7617abc1feee6608ca251cd32" + "version": "1.1.0-6", + "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-1.1.0-6.tgz", + "integrity": "sha512-HKaWwqfPOUSR3lMX1/2fQkgNoVnmhQtHyeGzE3kyf1j6BgAw4fzaHeoNLPLCLvq7c/SoxY2VXRxFCxq+1mB3JQ==" }, "wordwrap": { "version": "1.0.0", diff --git a/package.json b/package.json index 0a9138d4f..24b8bf3f0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "scripts": { "start": "npm run test:simple -- --watch --growl", - "test:base": "mocha tests --recursive", + "test:base": "mocha \"tests/lib/**/*.js\" \"tests/integrations/*.js\" --timeout 60000", "test:simple": "npm run test:base -- --reporter nyan", "test": "nyc npm run test:base", "lint": "eslint .", @@ -45,7 +45,7 @@ }, "dependencies": { "requireindex": "^1.1.0", - "vue-eslint-parser": "mysticatea/vue-eslint-parser#v1.1.0-4" + "vue-eslint-parser": "^1.1.0-6" }, "devDependencies": { "@types/node": "^4.2.6", diff --git a/tests/.eslintrc.json b/tests/.eslintrc.json new file mode 100644 index 000000000..4668ae79f --- /dev/null +++ b/tests/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "mocha": true + } +} diff --git a/tests/integrations/eslint-plugin-import.js b/tests/integrations/eslint-plugin-import.js new file mode 100644 index 000000000..e1908a636 --- /dev/null +++ b/tests/integrations/eslint-plugin-import.js @@ -0,0 +1,39 @@ +/** + * @author Toru Nagashima + * @copyright 2017 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +'use strict' + +// ----------------------------------------------------------------------------- +// Requirements +// ----------------------------------------------------------------------------- + +const cp = require('child_process') +const path = require('path') + +// ----------------------------------------------------------------------------- +// Tests +// ----------------------------------------------------------------------------- + +const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint` + +describe('Integration with eslint-plugin-import', () => { + let originalCwd + + before(() => { + originalCwd = process.cwd() + process.chdir(path.join(__dirname, 'eslint-plugin-import')) + cp.execSync('npm i', { stdio: 'inherit', env: { npm_config_package_lock: 'false' }}) + }) + after(() => { + process.chdir(originalCwd) + }) + + // https://github.com/vuejs/eslint-plugin-vue/issues/21#issuecomment-308957697 + // eslint-plugin-vue had been breaking eslint-plugin-import if people use both at the same time. + // This test is in order to prevent the regression. + it('should lint without errors', () => { + cp.execSync(`${ESLINT} a.vue`, { stdio: 'inherit' }) + }) +}) diff --git a/tests/integrations/eslint-plugin-import/.eslintrc.json b/tests/integrations/eslint-plugin-import/.eslintrc.json new file mode 100644 index 000000000..bd240b24b --- /dev/null +++ b/tests/integrations/eslint-plugin-import/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "root": true, + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2015 + }, + "parser": "vue-eslint-parser", + "plugins": [ + "import", + "vue" + ], + "rules": { + "import/default": "warn", + "import/namespace": "warn" + }, + "settings": { + "import/extensions": [ + ".js", + ".vue" + ] + } +} diff --git a/tests/integrations/eslint-plugin-import/a.vue b/tests/integrations/eslint-plugin-import/a.vue new file mode 100644 index 000000000..ce4b66e14 --- /dev/null +++ b/tests/integrations/eslint-plugin-import/a.vue @@ -0,0 +1,10 @@ + + + diff --git a/tests/integrations/eslint-plugin-import/b.vue b/tests/integrations/eslint-plugin-import/b.vue new file mode 100644 index 000000000..488aa4466 --- /dev/null +++ b/tests/integrations/eslint-plugin-import/b.vue @@ -0,0 +1,7 @@ + + + diff --git a/tests/integrations/eslint-plugin-import/package.json b/tests/integrations/eslint-plugin-import/package.json new file mode 100644 index 000000000..957cd9081 --- /dev/null +++ b/tests/integrations/eslint-plugin-import/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "name": "integration-test-for-eslint-plugin-import", + "version": "1.0.0", + "description": "Integration test for eslint-plugin-import", + "scripts": {}, + "keywords": [], + "author": "Toru Nagashima (https://github.com/mysticatea)", + "license": "MIT", + "dependencies": { + "eslint": "~3.19.0", + "eslint-plugin-import": "~2.3.0", + "eslint-plugin-vue": "file:../../.." + } +} diff --git a/tests/lib/rules/no-invalid-template-root.js b/tests/lib/rules/no-invalid-template-root.js index 6b7dbfd76..89a38c7b8 100644 --- a/tests/lib/rules/no-invalid-template-root.js +++ b/tests/lib/rules/no-invalid-template-root.js @@ -46,6 +46,10 @@ tester.run('no-invalid-template-root', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: `` } ], invalid: [ diff --git a/tests/lib/rules/no-invalid-v-else-if.js b/tests/lib/rules/no-invalid-v-else-if.js index 165fd3908..3763a8dcc 100644 --- a/tests/lib/rules/no-invalid-v-else-if.js +++ b/tests/lib/rules/no-invalid-v-else-if.js @@ -34,6 +34,10 @@ tester.run('no-invalid-v-else-if', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: `` } ], invalid: [ diff --git a/tests/lib/rules/no-invalid-v-else.js b/tests/lib/rules/no-invalid-v-else.js index b49667dce..30a2dc2b6 100644 --- a/tests/lib/rules/no-invalid-v-else.js +++ b/tests/lib/rules/no-invalid-v-else.js @@ -34,6 +34,10 @@ tester.run('no-invalid-v-else', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: `` } ], invalid: [