From 1c648cd962e6759bb9ec285ec03d191206e72ed4 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Sat, 13 Oct 2018 00:23:16 +0100 Subject: [PATCH] chore: init --- .gitignore | 8 ++++ .npmignore | 2 + .travis.yml | 4 ++ README.md | 31 ++++++++++++++ index.js | 77 +++++++++++++++++++++++++++++++++++ package.json | 47 +++++++++++++++++++++ renovate.json | 5 +++ tests/basic.test.js | 10 +++++ tests/validate-config.test.js | 14 +++++++ 9 files changed, 198 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json create mode 100644 renovate.json create mode 100644 tests/basic.test.js create mode 100644 tests/validate-config.test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..348180fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Dependencies +node_modules +package-lock.json +yarn.lock + +# Intellij idea +*.iml +.idea diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..21eb4b06 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.travis.yml +tests/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..59362a48 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: +- 8 +- 10 diff --git a/README.md b/README.md new file mode 100644 index 00000000..2da87ee6 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Nuxt ESLint Config + +[ESlint](https://eslint.org/) config used for Nuxt.js + +## Usage + +Do you want to add the config to your own projects? There you go: + +1. Add this package to your devDependencies (`npm i -D @nuxtjs/eslint-config` or `yarn add -D @nuxtjs/eslint-config`) +2. Add the [`peerDependencies`](./package.json) to your project + +`npm i -D eslint eslint-config-standard eslint-plugin-import eslint-plugin-jest eslint-plugin-node eslint-plugin-promise eslint-plugin-standard eslint-plugin-vue` + +3. Create a `.eslintrc.js` file + +4. Extend our config (you can use just the scope name as ESLint will assume the `eslint-config` prefix): + +```json +{ + "extends": [ + "@nuxtjs" + ] +} +``` + + +## License + +Setup inspired by [eslint-config-standard](https://github.com/standard/eslint-config-standard) + +MIT - Nuxt.js team diff --git a/index.js b/index.js new file mode 100644 index 00000000..78147772 --- /dev/null +++ b/index.js @@ -0,0 +1,77 @@ +module.exports = { + env: { + browser: true, + node: true, + 'jest/globals': true + }, + extends: [ + 'standard', + 'plugin:import/errors', + 'plugin:import/warnings', + 'plugin:vue/recommended' + ], + plugins: [ + 'vue', + 'jest' + ], + settings: { + 'import/resolver': { + node: { extensions: ['.js', '.mjs'] } + } + }, + rules: { + // Enforce import order + 'import/order': 2, + + // Imports should come first + 'import/first': 2, + + // Other import rules + 'import/no-mutable-exports': 2, + + // Allow unresolved imports + 'import/no-unresolved': 0, + + // Allow paren-less arrow functions only when there's no braces + 'arrow-parens': [2, 'as-needed', { requireForBlockBody: true }], + + // Allow async-await + 'generator-star-spacing': 0, + + // Allow debugger during development + 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, + + // Prefer const over let + 'prefer-const': [2, { + 'destructuring': 'any', + 'ignoreReadBeforeAssign': false + }], + + // No single if in an "else" block + 'no-lonely-if': 2, + + // Force curly braces for control flow + curly: 2, + + // No async function without await + 'require-await': 2, + + // Force dot notation when possible + 'dot-notation': 2, + + 'no-var': 2, + + // Do not allow console.logs etc... + 'no-console': 2, + 'space-before-function-paren': [2, { + anonymous: 'always', + named: 'never' + }], + 'vue/no-parsing-error': [2, { + 'x-invalid-end-tag': false + }], + 'vue/max-attributes-per-line': [2, { + 'singleline': 5 + }] + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..52f3cc50 --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "@nuxtjs/eslint-config", + "version": "0.0.1", + "description": "Nuxt.js eslint config", + "contributors": [ + "Alexander Lichter " + ], + "license": "MIT", + "homepage": "https://github.com/nuxt/eslint-config", + "repository": { + "type": "git", + "url": "git+https://github.com/nuxt/eslint-config.git" + }, + "bugs": { + "url": "https://github.com/nuxt/eslint-config/issues" + }, + "scripts": { + "lint": "eslint . --config=index.js", + "test": "npm run lint && jest", + "release": "standard-version && git push --follow-tags && npm publish" + }, + "files": [ + "index.js" + ], + "peerDependencies": { + "eslint": ">=5.0.0", + "eslint-config-standard": ">=12.0.0", + "eslint-plugin-import": ">=2.14.0", + "eslint-plugin-jest": ">=21.24.1", + "eslint-plugin-node": ">=7.0.1", + "eslint-plugin-promise": ">=4.0.1", + "eslint-plugin-standard": ">=4.0.0", + "eslint-plugin-vue": ">=5.0.0-beta.3" + }, + "devDependencies": { + "eslint": "^5.0.0", + "eslint-config-standard": "^12.0.0", + "eslint-plugin-import": "^2.14.0", + "eslint-plugin-jest": "^21.24.1", + "eslint-plugin-node": "^7.0.1", + "eslint-plugin-promise": "^4.0.1", + "eslint-plugin-standard": "^4.0.0", + "eslint-plugin-vue": "^5.0.0-beta.3", + "jest": "^23.6.0", + "standard-version": "^4.4.0" + } +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..217d8217 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "@nuxtjs" + ] +} diff --git a/tests/basic.test.js b/tests/basic.test.js new file mode 100644 index 00000000..eeacf105 --- /dev/null +++ b/tests/basic.test.js @@ -0,0 +1,10 @@ +const config = require('../') + +test('test basic properties of config', () => { + expect(isObject(config.env)).toBe(true) + expect(isObject(config.rules)).toBe(true) +}) + +function isObject(obj) { + return typeof obj === 'object' && obj !== null +} diff --git a/tests/validate-config.test.js b/tests/validate-config.test.js new file mode 100644 index 00000000..e57c8007 --- /dev/null +++ b/tests/validate-config.test.js @@ -0,0 +1,14 @@ +const eslint = require('eslint') + +test('load config in eslint to validate all rule syntax is correct', () => { + const CLIEngine = eslint.CLIEngine + + const cli = new CLIEngine({ + useEslintrc: false, + configFile: 'index.js' + }) + + const code = 'const foo = 1\nconst bar = function () {}\nbar(foo)\n' + + expect(cli.executeOnText(code).errorCount).toEqual(0) +})