├── .eslintignore ├── .github └── workflows │ └── ci-module.yml ├── .gitignore ├── API.md ├── LICENSE.md ├── README.md ├── lib └── index.js ├── package.json └── test ├── fixtures ├── arrow-parens.js ├── arrow-spacing.js ├── brace-style.js ├── camelcase.js ├── es6-env.js ├── handle-callback-err.js ├── hapi-capitalize-modules.js ├── hapi-for-you.js ├── hapi-scope-start.js ├── indent-switch-case.js ├── indent.js ├── key-spacing.js ├── no-arrowception.js ├── no-constant-condition.js ├── no-dupe-keys.js ├── no-extra-semi.js ├── no-shadow.js ├── no-undef.js ├── no-unsafe-finally.js ├── no-unused-vars.js ├── no-useless-computed-key.js ├── no-var.js ├── node-env.js ├── object-shorthand.js ├── one-var.js ├── prefer-arrow-callback.js ├── prefer-const.js ├── semi.js ├── space-before-blocks.js ├── space-before-function-paren.js └── strict.js └── index.js /.eslintignore: -------------------------------------------------------------------------------- 1 | test/fixtures 2 | 3 | -------------------------------------------------------------------------------- /.github/workflows/ci-module.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | test: 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | os: [ubuntu, windows, macos] 15 | node: ['*', '14', '12'] 16 | 17 | runs-on: ${{ matrix.os }}-latest 18 | name: ${{ matrix.os }} node@${{ matrix.node }} 19 | steps: 20 | - uses: actions/checkout@v2 21 | - uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node }} 24 | - name: install 25 | run: npm install 26 | - name: test 27 | run: npm test 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/package-lock.json 3 | 4 | coverage.* 5 | 6 | **/.DS_Store 7 | **/._* 8 | 9 | **/*.pem 10 | 11 | **/.vs 12 | **/.vscode 13 | **/.idea 14 | -------------------------------------------------------------------------------- /API.md: -------------------------------------------------------------------------------- 1 | 2 | ### Rules 3 | 4 | To use in your project, add `@hapi/eslint-config-hapi` and [`@hapi/eslint-plugin-hapi`](https://github.com/hapijs/eslint-plugin-hapi) to your `package.json`, then in your ESLint configuration add: 5 | 6 | ``` 7 | { 8 | "extends": "@hapi/eslint-config-hapi" 9 | } 10 | ``` 11 | 12 | **Note:** `@hapi/eslint-plugin-hapi` is a plugin containing custom hapi linting rules. It is a peer dependency because of the way ESLint handles shareable configs that include plugins and custom rules (see [eslint/eslint#3458](https://github.com/eslint/eslint/issues/3458) and [eslint/eslint#2518](https://github.com/eslint/eslint/issues/2518) for more background). 13 | 14 | 15 | | Rule | Option | 16 | |------|--------| 17 | | **'@hapi/hapi/capitalize-modules'** | ['warn', 'global-scope-only'] | 18 | | **'@hapi/hapi/for-loop'** | ['warn', { maxDepth: 3, startIterator: 'i' }] | 19 | | **'@hapi/hapi/no-var'** | 'error' | 20 | | **'@hapi/hapi/scope-start'** | 'warn' | 21 | | **'@hapi/hapi/no-arrowception'** | 'error' | 22 | | **'camelcase'** | 'off' | 23 | | **'consistent-return'** | 'off' | 24 | | **'vars-on-top'** | 'off' | 25 | | **'new-cap'** | 'off | 26 | | **'no-console'** | 'off' | 27 | | **'no-constant-condition'** | 'error' | 28 | | **'no-empty'** | 'off' | 29 | | **'no-native-reassign'** | 'off' | 30 | | **'no-underscore-dangle'** | 'off' | 31 | | **'no-undef'** | ['error', { typeof: false }] | 32 | | **'no-process-exit'** | 'off' | 33 | | **'no-unused-expressions'** | 'off' | 34 | | **'no-regex-spaces'** | 'off' | 35 | | **'no-catch-shadow'** | 'off' | 36 | | **'no-lonely-if'** | 'off' | 37 | | **'brace-style'** | ['warn', 'stroustrup'] | 38 | | **'no-shadow'** | ['warn', { allow: ['err', 'done'] }] | 39 | | **'no-unused-vars'** | ['warn', { vars: 'all', varsIgnorePattern: '^internals$', args: 'none' }] | 40 | | **'one-var'** | ['error', 'never'] | 41 | | **'handle-callback-err'** | ['error', '^(e\|err\|error)$'] | 42 | | **'array-bracket-spacing'** | 'warn' | 43 | | **'dot-notation'** | 'warn' | 44 | | **'eol-last'** | 'warn' | 45 | | **'no-trailing-spaces'** | 'warn' | 46 | | **'no-eq-null'** | 'warn' | 47 | | **'no-extend-native'** | 'warn' | 48 | | **'no-redeclare'** | 'warn' | 49 | | **'no-loop-func'** | 'warn' | 50 | | **'yoda'** | ['warn', 'never'] | 51 | | **'sort-vars'** | 'warn' | 52 | | **'arrow-parens'** | ['error', 'always'] | 53 | | **'arrow-spacing'** | ['error', { before: true, after: true }] | 54 | | **'quotes'** | ['error', 'single', { allowTemplateLiterals: true }] | 55 | | **'consistent-this'** | ['error', 'self'] | 56 | | **'new-parens'** | 'error' | 57 | | **'no-array-constructor'** | 'error' | 58 | | **'no-confusing-arrow'** | 'error' | 59 | | **'no-new-object'** | 'error' | 60 | | **'no-spaced-func'** | 'error' | 61 | | **'no-mixed-spaces-and-tabs'** | 'error' | 62 | | **'key-spacing'** | 'error' | 63 | | **'keyword-spacing'** | ['error', { before: true, after: true }] | 64 | | **'semi'** | ['error', 'always'] | 65 | | **'semi-spacing'** | ['error', { before: false, after: true }] | 66 | | **'space-before-blocks'** | 'error' | 67 | | **'space-infix-ops'** | 'error' | 68 | | **'space-unary-ops'** | ['warn', { words: true, nonwords: false }] | 69 | | **'strict'** | ['error', 'global'] | 70 | | **'eqeqeq'** | 'error' | 71 | | **'curly'** | ['error', 'all'] | 72 | | **'no-eval'** | 'error' | 73 | | **'no-else-return'** | 'error' | 74 | | **'no-return-assign'** | 'error' | 75 | | **'no-new-wrappers'** | 'error' | 76 | | **'comma-dangle'** | ['error', 'never'] | 77 | | **'no-sparse-arrays'** | 'error' | 78 | | **'no-ex-assign'** | 'error' | 79 | | **'prefer-arrow-callback'** | 'error' | 80 | | **'prefer-const'** | ['error', { destructuring: 'all' }] | 81 | | **'indent'** | ['error', 4, { SwitchCase: 1 }] | 82 | | **'space-before-function-paren'** | ['error', { anonymous: 'always', named: 'never' }] | 83 | | **'func-style'** | ['error', 'expression'] | 84 | | **'object-curly-spacing'** | ['error', 'always'] | 85 | | **'object-shorthand'** | ['error', 'properties'] | 86 | | **'no-unsafe-finally'** | 'error' | 87 | | **'no-useless-computed-key'** | 'error' | 88 | | **'require-await'** | 'error' | 89 | | **'constructor-super'** | 'error' | 90 | | **'no-buffer-constructor'** | 'error' | 91 | | **'no-mixed-requires'** | 'error' | 92 | | **'no-new-require'** | 'error' | 93 | | **'no-caller'** | 'error' | 94 | | **'no-const-assign'** | 'error' | 95 | | **'no-dupe-class-members'** | 'error' | 96 | | **'no-class-assign'** | 'warn' | 97 | | **'no-new-symbol'** | 'error | 98 | | **'no-this-before-super'** | 'error' | 99 | | **'prefer-rest-params'** | 'error' | 100 | | **'prefer-spread'** | 'error' | 101 | | **'no-useless-call'** | 'error' | 102 | | **'rest-spread-spacing'** | ['error', 'never'] | 103 | | **'no-extra-semi'** | 'error' | 104 | | **'no-dupe-keys'** | 'error' | 105 | | **'padding-line-between-statements'** | [
'error',
{ blankLine: 'always', prev: 'directive', next: '\*' },
{ blankLine: 'any', prev: 'directive', next: 'directive' },
{ blankLine: 'always', prev: 'cjs-import', next: '\*' },
{ blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' },
{ blankLine: 'always', prev: 'cjs-export', next: '\*' },
{ blankLine: 'always', prev: 'multiline-block-like', next: '\*' },
{ blankLine: 'always', prev: 'class', next: '\*' }
] | 106 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019-2020, Sideway Inc, and project contributors 2 | Copyright (c) 2015-2019 Colin J. Ihrig 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | * The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | 3 | This package is now deprecated in favor of [`@hapi/eslint-config`](https://hapi.dev/module/eslint-plugin/). Please migrate to the plugin if you want to use hapi's ESLint configuration. 4 | 5 | 6 | 7 | # @hapi/eslint-config-hapi 8 | 9 | #### Shareable ESLint config for the hapi ecosystem. 10 | 11 | **eslint-config-hapi** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together. 12 | 13 | ### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support 14 | 15 | ## Useful resources 16 | 17 | - [Documentation and API](https://hapi.dev/module/eslint-config-hapi/) 18 | - [Versions status](https://hapi.dev/resources/status/#eslint-config-hapi) 19 | - [Changelog](https://hapi.dev/family/eslint-config-hapi/changelog/) 20 | - [Project policies](https://hapi.dev/policies/) 21 | - [Free and commercial support options](https://hapi.dev/support/) 22 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | plugins: ['@hapi/eslint-plugin-hapi'], 5 | env: { 6 | node: true, 7 | es2020: true 8 | }, 9 | parserOptions: { 10 | ecmaVersion: 2020 11 | }, 12 | rules: { 13 | '@hapi/hapi/capitalize-modules': ['warn', 'global-scope-only'], 14 | '@hapi/hapi/for-loop': ['warn', { maxDepth: 3, startIterator: 'i' }], 15 | '@hapi/hapi/no-var': 'error', 16 | '@hapi/hapi/scope-start': 'warn', 17 | '@hapi/hapi/no-arrowception': 'error', 18 | 'camelcase': 'off', 19 | 'consistent-return': 'off', 20 | 'vars-on-top': 'off', 21 | 'new-cap': 'off', 22 | 'no-console': 'off', 23 | 'no-constant-condition': 'error', 24 | 'no-empty': 'off', 25 | 'no-native-reassign': 'off', 26 | 'no-underscore-dangle': 'off', 27 | 'no-undef': ['error', { typeof: false }], 28 | 'no-process-exit': 'off', 29 | 'no-unused-expressions': 'off', 30 | 'no-regex-spaces': 'off', 31 | 'no-catch-shadow': 'off', 32 | 'no-lonely-if': 'off', 33 | 'brace-style': ['warn', 'stroustrup'], 34 | 'no-shadow': ['warn', { allow: ['err', 'done'] }], 35 | 'no-unused-vars': ['warn', { vars: 'all', varsIgnorePattern: '^internals$', args: 'none' }], 36 | 'one-var': ['error', 'never'], 37 | 'handle-callback-err': ['error', '^(e|err|error)$'], 38 | 'array-bracket-spacing': 'warn', 39 | 'dot-notation': 'warn', 40 | 'eol-last': 'warn', 41 | 'no-trailing-spaces': 'warn', 42 | 'no-eq-null': 'warn', 43 | 'no-extend-native': 'warn', 44 | 'no-redeclare': 'warn', 45 | 'no-loop-func': 'warn', 46 | 'yoda': ['warn', 'never'], 47 | 'sort-vars': 'warn', 48 | 'arrow-parens': ['error', 'always'], 49 | 'arrow-spacing': ['error', { before: true, after: true }], 50 | 'quotes': ['error', 'single', { allowTemplateLiterals: true }], 51 | 'consistent-this': ['error', 'self'], 52 | 'new-parens': 'error', 53 | 'no-array-constructor': 'error', 54 | 'no-confusing-arrow': 'error', 55 | 'no-new-object': 'error', 56 | 'no-spaced-func': 'error', 57 | 'no-mixed-spaces-and-tabs': 'error', 58 | 'key-spacing': 'error', 59 | 'keyword-spacing': ['error', { before: true, after: true }], 60 | 'semi': ['error', 'always'], 61 | 'semi-spacing': ['error', { before: false, after: true }], 62 | 'space-before-blocks': 'error', 63 | 'space-infix-ops': 'error', 64 | 'space-unary-ops': ['warn', { words: true, nonwords: false }], 65 | 'strict': ['error', 'global'], 66 | 'eqeqeq': 'error', 67 | 'curly': ['error', 'all'], 68 | 'no-eval': 'error', 69 | 'no-else-return': 'error', 70 | 'no-return-assign': 'error', 71 | 'no-new-wrappers': 'error', 72 | 'comma-dangle': ['error', 'never'], 73 | 'no-sparse-arrays': 'error', 74 | 'no-ex-assign': 'error', 75 | 'prefer-arrow-callback': 'error', 76 | 'prefer-const': ['error', { destructuring: 'all' }], 77 | 'indent': ['error', 4, { SwitchCase: 1 }], 78 | 'space-before-function-paren': ['error', { anonymous: 'always', named: 'never' }], 79 | 'func-style': ['error', 'expression'], 80 | 'object-curly-spacing': ['error', 'always'], 81 | 'object-shorthand': ['error', 'properties'], 82 | 'no-unsafe-finally': 'error', 83 | 'no-useless-computed-key': 'error', 84 | 'require-await': 'error', 85 | 'constructor-super': 'error', 86 | 'no-buffer-constructor': 'error', 87 | 'no-mixed-requires': 'error', 88 | 'no-new-require': 'error', 89 | 'no-caller': 'error', 90 | 'no-const-assign': 'error', 91 | 'no-dupe-class-members': 'error', 92 | 'no-class-assign': 'warn', 93 | 'no-new-symbol': 'error', 94 | 'no-this-before-super': 'error', 95 | 'prefer-rest-params': 'error', 96 | 'prefer-spread': 'error', 97 | 'no-useless-call': 'error', 98 | 'rest-spread-spacing': ['error', 'never'], 99 | 'no-extra-semi': 'error', 100 | 'no-dupe-keys': 'error', 101 | 'padding-line-between-statements': [ 102 | 'error', 103 | { blankLine: 'always', prev: 'directive', next: '*' }, 104 | { blankLine: 'any', prev: 'directive', next: 'directive' }, 105 | { blankLine: 'always', prev: 'cjs-import', next: '*' }, 106 | { blankLine: 'any', prev: 'cjs-import', next: 'cjs-import' }, 107 | { blankLine: 'always', prev: 'cjs-export', next: '*' }, 108 | { blankLine: 'always', prev: 'multiline-block-like', next: '*' }, 109 | { blankLine: 'always', prev: 'class', next: '*' } 110 | ] 111 | } 112 | }; 113 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@hapi/eslint-config-hapi", 3 | "version": "13.0.2", 4 | "description": "Shareable ESLint config for the hapi ecosystem", 5 | "main": "lib/index.js", 6 | "repository": "https://github.com/hapijs/eslint-config-hapi.git", 7 | "files": [ 8 | "lib" 9 | ], 10 | "keywords": [ 11 | "hapi", 12 | "lint", 13 | "eslint", 14 | "eslintconfig" 15 | ], 16 | "dependencies": {}, 17 | "peerDependencies": { 18 | "@hapi/eslint-plugin-hapi": "4.x.x" 19 | }, 20 | "devDependencies": { 21 | "@hapi/code": "8.x.x", 22 | "@hapi/eslint-plugin-hapi": "4.x.x", 23 | "@hapi/lab": "22.x.x", 24 | "eslint": "7.x.x" 25 | }, 26 | "scripts": { 27 | "test": "lab -a @hapi/code -t 100 -L" 28 | }, 29 | "license": "BSD-3-Clause" 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/arrow-parens.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars */ 2 | const foo = bar => { 3 | 4 | return bar + 1; 5 | }; 6 | 7 | const baz = (quux) => { 8 | 9 | return quux + 1; 10 | }; 11 | -------------------------------------------------------------------------------- /test/fixtures/arrow-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars */ 2 | const foo = (bar)=> { 3 | 4 | return bar + 1; 5 | }; 6 | 7 | const baz = (quux) =>{ 8 | 9 | return quux + 1; 10 | }; 11 | 12 | const fn = (arg) => { 13 | 14 | return arg + 1; 15 | }; 16 | -------------------------------------------------------------------------------- /test/fixtures/brace-style.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable keyword-spacing */ 2 | 'use strict'; 3 | 4 | const foo = true; 5 | let bar = 0; 6 | 7 | if (foo) { 8 | bar = 1; 9 | } else { 10 | bar = 2; 11 | } 12 | 13 | if (foo) { 14 | bar = 3; 15 | } 16 | else { 17 | bar = 4; 18 | } 19 | 20 | return bar; 21 | -------------------------------------------------------------------------------- /test/fixtures/camelcase.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | const foo_bar = '123'; 3 | const barBaz = '456'; 4 | 5 | return foo_bar + barBaz; 6 | -------------------------------------------------------------------------------- /test/fixtures/es6-env.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | module.exports = `__filename = ${__filename}`; 3 | -------------------------------------------------------------------------------- /test/fixtures/handle-callback-err.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | module.exports.foo = function (value) { 5 | 6 | const top = function (err) { 7 | 8 | const inner = function (e) { 9 | 10 | return value; 11 | }; 12 | }; 13 | 14 | top(); 15 | }; 16 | 17 | 18 | module.exports.bar = function (value) { 19 | 20 | const top = function (abc) { 21 | 22 | const inner = function (xyz) { 23 | 24 | return value; 25 | }; 26 | }; 27 | 28 | top(); 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/hapi-capitalize-modules.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const Fs = require('fs'); 5 | const net = require('net'); 6 | 7 | const fn = function () { 8 | 9 | const Assert = require('assert'); 10 | const dgram = require('dgram'); 11 | }; 12 | 13 | fn(); 14 | -------------------------------------------------------------------------------- /test/fixtures/hapi-for-you.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const arr = []; 5 | 6 | for (let i = 0; i < arr.length; ++i) { 7 | for (let k = 0; k < arr.length; k++) { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/hapi-scope-start.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars */ 2 | const foo = function () { 3 | return 'there should be a blank line before this line'; 4 | }; 5 | 6 | const bar = function () { 7 | 8 | return 'no lint errors'; 9 | }; 10 | 11 | const baz = () => { 12 | 13 | return 'no lint errors'; 14 | }; 15 | 16 | const quux = () => 85; // no lint errors 17 | 18 | const buux = () => ({ 19 | a: 'b' 20 | }); 21 | -------------------------------------------------------------------------------- /test/fixtures/indent-switch-case.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const foo = 'foo'; 4 | let result = 0; 5 | 6 | switch (foo) { 7 | case 'foo': 8 | result = 1; 9 | break; 10 | 11 | case 'bar': 12 | result = 2; 13 | break; 14 | case 'baz': 15 | result = 3; 16 | break; 17 | } 18 | 19 | return result; 20 | -------------------------------------------------------------------------------- /test/fixtures/indent.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | module.exports.foo = function (value) { 3 | 4 | return value + 1; 5 | }; 6 | 7 | 8 | module.exports.foo = function (value) { 9 | 10 | return value + 1; 11 | }; 12 | -------------------------------------------------------------------------------- /test/fixtures/key-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars */ 2 | const a = { 3 | b: 'c', 4 | c : 'd' 5 | }; 6 | -------------------------------------------------------------------------------- /test/fixtures/no-arrowception.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars */ 2 | const foo = () => () => 85; 3 | const bar = () => 85; 4 | -------------------------------------------------------------------------------- /test/fixtures/no-constant-condition.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | if ((foo) => 1) { 5 | // Do nothing 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/no-dupe-keys.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const obj = { 5 | a: 1, 6 | a: 2 7 | }; 8 | -------------------------------------------------------------------------------- /test/fixtures/no-extra-semi.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable padding-line-between-statements,strict */ 2 | 3 | module.exports.foo = function () { 4 | 5 | try { 6 | 7 | } 8 | catch (e) { 9 | 10 | }; 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /test/fixtures/no-shadow.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, no-unused-vars, handle-callback-err */ 2 | 3 | 4 | // Declare internals 5 | 6 | const internals = {}; 7 | 8 | 9 | module.exports.foo = function (value) { 10 | 11 | const top = function (err) { 12 | 13 | const inner = function (err) { 14 | 15 | return value; 16 | }; 17 | }; 18 | 19 | top(); 20 | }; 21 | 22 | 23 | module.exports.bar = function (value) { 24 | 25 | const top = function (res) { 26 | 27 | const inner = function (res) { 28 | 29 | return value; 30 | }; 31 | }; 32 | 33 | top(); 34 | }; 35 | -------------------------------------------------------------------------------- /test/fixtures/no-undef.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | try { 5 | const foo = typeof bar; 6 | const baz = bar; 7 | } 8 | catch (ignoreErr) { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/no-unsafe-finally.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | module.exports.foo = function () { 3 | 4 | try { 5 | return 1; 6 | } 7 | catch (err) { 8 | 9 | return 2; 10 | } 11 | finally { 12 | return 3; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /test/fixtures/no-unused-vars.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | const internals = {}; 3 | const internals2 = {}; 4 | const bar = function (foo) { 5 | 6 | }; 7 | 8 | return bar; 9 | -------------------------------------------------------------------------------- /test/fixtures/no-useless-computed-key.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict, padding-line-between-statements */ 2 | module.exports.a = { ['0']: 0 }; 3 | module.exports.a = { ['0+1,234']: 0 }; 4 | module.exports.a = { [0]: 0 }; 5 | module.exports.a = { ['x']: 0 }; 6 | module.exports.a = { ['x']() {} }; 7 | -------------------------------------------------------------------------------- /test/fixtures/no-var.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | var foo = 1; 5 | let bar = 2; 6 | const baz = 3; 7 | 8 | bar = 4; 9 | -------------------------------------------------------------------------------- /test/fixtures/node-env.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | const Fs = require('fs'); 3 | 4 | module.exports = Fs; 5 | -------------------------------------------------------------------------------- /test/fixtures/object-shorthand.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const a = 1; 5 | const b = 2; 6 | const c = function () {}; 7 | const d = function () {}; 8 | const obj = { 9 | a, 10 | b: b, 11 | c: function () {}, 12 | d() {} 13 | }; 14 | -------------------------------------------------------------------------------- /test/fixtures/one-var.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars, prefer-const */ 2 | 'use strict'; 3 | 4 | const foo = 1; 5 | let bar; 6 | let baz, quux; 7 | 8 | bar = 1; 9 | -------------------------------------------------------------------------------- /test/fixtures/prefer-arrow-callback.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars, handle-callback-err */ 2 | 'use strict'; 3 | 4 | const foo = (arg, callback) => { 5 | 6 | return callback(null, arg + 1); 7 | }; 8 | 9 | const bar = function (err, value) { 10 | 11 | }; 12 | 13 | const baz = (err, value) => { 14 | 15 | }; 16 | 17 | foo(1, bar); 18 | foo(2, baz); 19 | foo(3, (err, value) => { 20 | 21 | }); 22 | foo(4, function (err, value) { 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /test/fixtures/prefer-const.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | let foo = 1; 5 | let bar = 2; 6 | const baz = 3; 7 | 8 | bar++; 9 | 10 | let { a, b } = { a: 1, b: 2 }; 11 | a++; 12 | -------------------------------------------------------------------------------- /test/fixtures/semi.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable strict */ 2 | module.exports.foo = function () { 3 | 4 | return 42 5 | }; 6 | 7 | module.exports.bar = function () { 8 | 9 | return 85; 10 | }; 11 | -------------------------------------------------------------------------------- /test/fixtures/space-before-blocks.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const foo = function (){ 5 | 6 | }; 7 | 8 | const bar = function () { 9 | 10 | }; 11 | 12 | const baz = function (){}; 13 | -------------------------------------------------------------------------------- /test/fixtures/space-before-function-paren.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | 'use strict'; 3 | 4 | const foo = function () { 5 | 6 | }; 7 | 8 | const bar = function() { 9 | 10 | }; 11 | 12 | const baz = function baz() { 13 | 14 | }; 15 | 16 | const quux = function quux () { 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /test/fixtures/strict.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | const foo = 'this should be using strict mode but isnt'; 3 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Fs = require('fs'); 4 | const Path = require('path'); 5 | 6 | const Code = require('@hapi/code'); 7 | const ESLint = require('eslint'); 8 | const Lab = require('@hapi/lab'); 9 | const Config = require('..'); 10 | 11 | 12 | const internals = {}; 13 | 14 | 15 | const { describe, it } = exports.lab = Lab.script(); 16 | const expect = Code.expect; 17 | 18 | 19 | Code.settings.truncateMessages = false; 20 | 21 | 22 | internals.lintFile = function (file) { 23 | 24 | const cli = new ESLint.CLIEngine({ 25 | useEslintrc: false, 26 | baseConfig: Config 27 | }); 28 | 29 | const data = Fs.readFileSync(Path.join(__dirname, file), 'utf8'); 30 | return cli.executeOnText(data); 31 | }; 32 | 33 | 34 | describe('eslint-config', () => { 35 | 36 | it('enforces file level strict mode', () => { 37 | 38 | const output = internals.lintFile('fixtures/strict.js'); 39 | const results = output.results[0]; 40 | 41 | expect(output.errorCount).to.equal(1); 42 | expect(output.warningCount).to.equal(0); 43 | expect(results.errorCount).to.equal(1); 44 | expect(results.warningCount).to.equal(0); 45 | 46 | const msg = results.messages[0]; 47 | 48 | expect(msg.ruleId).to.equal('strict'); 49 | expect(msg.severity).to.equal(2); 50 | expect(msg.message).to.equal('Use the global form of \'use strict\'.'); 51 | expect(msg.line).to.equal(2); 52 | expect(msg.column).to.equal(1); 53 | expect(msg.nodeType).to.equal('Program'); 54 | }); 55 | 56 | it('enforces stroustrup style braces', () => { 57 | 58 | const output = internals.lintFile('fixtures/brace-style.js'); 59 | const results = output.results[0]; 60 | 61 | expect(output.errorCount).to.equal(0); 62 | expect(output.warningCount).to.equal(1); 63 | expect(results.errorCount).to.equal(0); 64 | expect(results.warningCount).to.equal(1); 65 | 66 | const msg = results.messages[0]; 67 | 68 | expect(msg.ruleId).to.equal('brace-style'); 69 | expect(msg.severity).to.equal(1); 70 | expect(msg.message).to.equal('Closing curly brace appears on the same line as the subsequent block.'); 71 | expect(msg.line).to.equal(9); 72 | expect(msg.column).to.equal(1); 73 | expect(msg.nodeType).to.equal('Punctuator'); 74 | }); 75 | 76 | it('enforces four space indentation', () => { 77 | 78 | const output = internals.lintFile('fixtures/indent.js'); 79 | const results = output.results[0]; 80 | 81 | expect(output.errorCount).to.equal(1); 82 | expect(output.warningCount).to.equal(0); 83 | expect(results.errorCount).to.equal(1); 84 | expect(results.warningCount).to.equal(0); 85 | 86 | const msg = results.messages[0]; 87 | 88 | expect(msg.ruleId).to.equal('indent'); 89 | expect(msg.severity).to.equal(2); 90 | expect(msg.message).to.equal('Expected indentation of 4 spaces but found 2.'); 91 | expect(msg.line).to.equal(4); 92 | expect(msg.column).to.equal(1); 93 | expect(msg.nodeType).to.equal('Keyword'); 94 | }); 95 | 96 | it('enforces case indentation in switch statements', () => { 97 | 98 | const output = internals.lintFile('fixtures/indent-switch-case.js'); 99 | const results = output.results[0]; 100 | 101 | expect(output.errorCount).to.equal(5); 102 | expect(output.warningCount).to.equal(0); 103 | expect(results.errorCount).to.equal(5); 104 | expect(results.warningCount).to.equal(0); 105 | 106 | let msg = results.messages[0]; 107 | 108 | expect(msg.ruleId).to.equal('indent'); 109 | expect(msg.severity).to.equal(2); 110 | expect(msg.message).to.equal('Expected indentation of 4 spaces but found 0.'); 111 | expect(msg.line).to.equal(11); 112 | expect(msg.column).to.equal(1); 113 | expect(msg.nodeType).to.equal('Keyword'); 114 | 115 | msg = results.messages[1]; 116 | 117 | expect(msg.ruleId).to.equal('indent'); 118 | expect(msg.severity).to.equal(2); 119 | expect(msg.message).to.equal('Expected indentation of 8 spaces but found 4.'); 120 | expect(msg.line).to.equal(12); 121 | expect(msg.column).to.equal(1); 122 | expect(msg.nodeType).to.equal('Identifier'); 123 | 124 | msg = results.messages[2]; 125 | 126 | expect(msg.ruleId).to.equal('indent'); 127 | expect(msg.severity).to.equal(2); 128 | expect(msg.message).to.equal('Expected indentation of 8 spaces but found 4.'); 129 | expect(msg.line).to.equal(13); 130 | expect(msg.column).to.equal(1); 131 | expect(msg.nodeType).to.equal('Keyword'); 132 | 133 | msg = results.messages[3]; 134 | 135 | expect(msg.ruleId).to.equal('indent'); 136 | expect(msg.severity).to.equal(2); 137 | expect(msg.message).to.equal('Expected indentation of 8 spaces but found 4.'); 138 | expect(msg.line).to.equal(15); 139 | expect(msg.column).to.equal(1); 140 | expect(msg.nodeType).to.equal('Identifier'); 141 | 142 | msg = results.messages[4]; 143 | 144 | expect(msg.ruleId).to.equal('indent'); 145 | expect(msg.severity).to.equal(2); 146 | expect(msg.message).to.equal('Expected indentation of 8 spaces but found 4.'); 147 | expect(msg.line).to.equal(16); 148 | expect(msg.column).to.equal(1); 149 | expect(msg.nodeType).to.equal('Keyword'); 150 | }); 151 | 152 | it('enforces semicolon usage', () => { 153 | 154 | const output = internals.lintFile('fixtures/semi.js'); 155 | const results = output.results[0]; 156 | 157 | expect(output.errorCount).to.equal(1); 158 | expect(output.warningCount).to.equal(0); 159 | expect(results.errorCount).to.equal(1); 160 | expect(results.warningCount).to.equal(0); 161 | 162 | const msg = results.messages[0]; 163 | 164 | expect(msg.ruleId).to.equal('semi'); 165 | expect(msg.severity).to.equal(2); 166 | expect(msg.message).to.equal('Missing semicolon.'); 167 | expect(msg.line).to.equal(4); 168 | expect(msg.column).to.equal(14); 169 | expect(msg.nodeType).to.equal('ReturnStatement'); 170 | }); 171 | 172 | it('enforces no extra semicolons', () => { 173 | 174 | const output = internals.lintFile('fixtures/no-extra-semi.js'); 175 | const results = output.results[0]; 176 | 177 | expect(output.errorCount).to.equal(1); 178 | expect(output.warningCount).to.equal(0); 179 | expect(results.errorCount).to.equal(1); 180 | expect(results.warningCount).to.equal(0); 181 | 182 | const msg = results.messages[0]; 183 | 184 | expect(msg.ruleId).to.equal('no-extra-semi'); 185 | expect(msg.severity).to.equal(2); 186 | expect(msg.message).to.equal('Unnecessary semicolon.'); 187 | expect(msg.line).to.equal(10); 188 | expect(msg.column).to.equal(6); 189 | expect(msg.nodeType).to.equal('EmptyStatement'); 190 | }); 191 | 192 | it('enforces space-before-function-paren', () => { 193 | 194 | const output = internals.lintFile('fixtures/space-before-function-paren.js'); 195 | const results = output.results[0]; 196 | 197 | expect(output.errorCount).to.equal(2); 198 | expect(output.warningCount).to.equal(0); 199 | expect(results.errorCount).to.equal(2); 200 | expect(results.warningCount).to.equal(0); 201 | 202 | let msg = results.messages[0]; 203 | 204 | expect(msg.ruleId).to.equal('space-before-function-paren'); 205 | expect(msg.severity).to.equal(2); 206 | expect(msg.message).to.equal('Missing space before function parentheses.'); 207 | expect(msg.line).to.equal(8); 208 | expect(msg.column).to.equal(21); 209 | expect(msg.nodeType).to.equal('FunctionExpression'); 210 | 211 | msg = results.messages[1]; 212 | 213 | expect(msg.ruleId).to.equal('space-before-function-paren'); 214 | expect(msg.severity).to.equal(2); 215 | expect(msg.message).to.equal('Unexpected space before function parentheses.'); 216 | expect(msg.line).to.equal(16); 217 | expect(msg.column).to.equal(27); 218 | expect(msg.nodeType).to.equal('FunctionExpression'); 219 | }); 220 | 221 | it('enforces @hapi/hapi/for-loop', () => { 222 | 223 | const output = internals.lintFile('fixtures/hapi-for-you.js'); 224 | const results = output.results[0]; 225 | 226 | expect(output.errorCount).to.equal(0); 227 | expect(output.warningCount).to.equal(2); 228 | expect(results.errorCount).to.equal(0); 229 | expect(results.warningCount).to.equal(2); 230 | 231 | let msg = results.messages[0]; 232 | 233 | expect(msg.ruleId).to.equal('@hapi/hapi/for-loop'); 234 | expect(msg.severity).to.equal(1); 235 | expect(msg.message).to.equal('Expected iterator \'j\', but got \'k\'.'); 236 | expect(msg.line).to.equal(7); 237 | expect(msg.column).to.equal(5); 238 | expect(msg.nodeType).to.equal('ForStatement'); 239 | 240 | msg = results.messages[1]; 241 | 242 | expect(msg.ruleId).to.equal('@hapi/hapi/for-loop'); 243 | expect(msg.severity).to.equal(1); 244 | expect(msg.message).to.equal('Update to iterator should use prefix operator.'); 245 | expect(msg.line).to.equal(7); 246 | expect(msg.column).to.equal(5); 247 | expect(msg.nodeType).to.equal('ForStatement'); 248 | }); 249 | 250 | it('enforces @hapi/hapi/scope-start', () => { 251 | 252 | const output = internals.lintFile('fixtures/hapi-scope-start.js'); 253 | const results = output.results[0]; 254 | 255 | expect(output.errorCount).to.equal(0); 256 | expect(output.warningCount).to.equal(1); 257 | expect(results.errorCount).to.equal(0); 258 | expect(results.warningCount).to.equal(1); 259 | 260 | const msg = results.messages[0]; 261 | 262 | expect(msg.ruleId).to.equal('@hapi/hapi/scope-start'); 263 | expect(msg.severity).to.equal(1); 264 | expect(msg.message).to.equal('Missing blank line at beginning of function.'); 265 | expect(msg.line).to.equal(2); 266 | expect(msg.column).to.equal(13); 267 | expect(msg.nodeType).to.equal('FunctionExpression'); 268 | }); 269 | 270 | it('enforces @hapi/hapi/capitalize-modules', () => { 271 | 272 | const output = internals.lintFile('fixtures/hapi-capitalize-modules.js'); 273 | const results = output.results[0]; 274 | 275 | expect(output.errorCount).to.equal(0); 276 | expect(output.warningCount).to.equal(1); 277 | expect(results.errorCount).to.equal(0); 278 | expect(results.warningCount).to.equal(1); 279 | 280 | const msg = results.messages[0]; 281 | 282 | expect(msg.ruleId).to.equal('@hapi/hapi/capitalize-modules'); 283 | expect(msg.severity).to.equal(1); 284 | expect(msg.message).to.equal('Imported module variable name not capitalized.'); 285 | expect(msg.line).to.equal(5); 286 | expect(msg.column).to.equal(7); 287 | expect(msg.nodeType).to.equal('VariableDeclarator'); 288 | }); 289 | 290 | it('enforces @hapi/hapi/no-arrowception', () => { 291 | 292 | const output = internals.lintFile('fixtures/no-arrowception.js'); 293 | const results = output.results[0]; 294 | 295 | expect(output.errorCount).to.equal(1); 296 | expect(output.warningCount).to.equal(0); 297 | expect(results.errorCount).to.equal(1); 298 | expect(results.warningCount).to.equal(0); 299 | 300 | const msg = results.messages[0]; 301 | 302 | expect(msg.ruleId).to.equal('@hapi/hapi/no-arrowception'); 303 | expect(msg.severity).to.equal(2); 304 | expect(msg.message).to.equal('Arrow function implicitly creates arrow function.'); 305 | expect(msg.line).to.equal(2); 306 | expect(msg.column).to.equal(13); 307 | expect(msg.nodeType).to.equal('ArrowFunctionExpression'); 308 | }); 309 | 310 | it('enforces no-shadow rule', () => { 311 | 312 | const output = internals.lintFile('fixtures/no-shadow.js'); 313 | const results = output.results[0]; 314 | 315 | expect(output.errorCount).to.equal(0); 316 | expect(output.warningCount).to.equal(1); 317 | expect(results.errorCount).to.equal(0); 318 | expect(results.warningCount).to.equal(1); 319 | 320 | const msg = results.messages[0]; 321 | 322 | expect(msg.ruleId).to.equal('no-shadow'); 323 | expect(msg.severity).to.equal(1); 324 | expect(msg.message).to.equal('\'res\' is already declared in the upper scope.'); 325 | expect(msg.line).to.equal(27); 326 | expect(msg.column).to.equal(33); 327 | expect(msg.nodeType).to.equal('Identifier'); 328 | }); 329 | 330 | it('enforces one-var rule', () => { 331 | 332 | const output = internals.lintFile('fixtures/one-var.js'); 333 | const results = output.results[0]; 334 | 335 | expect(output.errorCount).to.equal(1); 336 | expect(output.warningCount).to.equal(0); 337 | expect(results.errorCount).to.equal(1); 338 | expect(results.warningCount).to.equal(0); 339 | 340 | const msg = results.messages[0]; 341 | 342 | expect(msg.ruleId).to.equal('one-var'); 343 | expect(msg.severity).to.equal(2); 344 | expect(msg.message).to.equal('Split \'let\' declarations into multiple statements.'); 345 | expect(msg.line).to.equal(6); 346 | expect(msg.column).to.equal(1); 347 | expect(msg.nodeType).to.equal('VariableDeclaration'); 348 | }); 349 | 350 | it('enforces no-undef rule', () => { 351 | 352 | const output = internals.lintFile('fixtures/no-undef.js'); 353 | const results = output.results[0]; 354 | 355 | expect(output.errorCount).to.equal(1); 356 | expect(output.warningCount).to.equal(0); 357 | expect(results.errorCount).to.equal(1); 358 | expect(results.warningCount).to.equal(0); 359 | 360 | const msg = results.messages[0]; 361 | 362 | expect(msg.ruleId).to.equal('no-undef'); 363 | expect(msg.severity).to.equal(2); 364 | expect(msg.message).to.equal('\'bar\' is not defined.'); 365 | expect(msg.line).to.equal(6); 366 | expect(msg.column).to.equal(17); 367 | expect(msg.nodeType).to.equal('Identifier'); 368 | }); 369 | 370 | it('enforces no-unused-vars', () => { 371 | 372 | const output = internals.lintFile('fixtures/no-unused-vars.js'); 373 | const results = output.results[0]; 374 | 375 | expect(output.errorCount).to.equal(0); 376 | expect(output.warningCount).to.equal(1); 377 | expect(results.errorCount).to.equal(0); 378 | expect(results.warningCount).to.equal(1); 379 | 380 | const msg = results.messages[0]; 381 | 382 | expect(msg.ruleId).to.equal('no-unused-vars'); 383 | expect(msg.severity).to.equal(1); 384 | expect(msg.message).to.match(/'internals2' is assigned a value but never used\./); 385 | expect(msg.line).to.equal(3); 386 | expect(msg.column).to.equal(7); 387 | expect(msg.nodeType).to.equal('Identifier'); 388 | }); 389 | 390 | it('enforces prefer-const', () => { 391 | 392 | const output = internals.lintFile('fixtures/prefer-const.js'); 393 | const results = output.results[0]; 394 | 395 | expect(output.errorCount).to.equal(1); 396 | expect(output.warningCount).to.equal(0); 397 | expect(results.errorCount).to.equal(1); 398 | expect(results.warningCount).to.equal(0); 399 | 400 | const msg = results.messages[0]; 401 | 402 | expect(msg.ruleId).to.equal('prefer-const'); 403 | expect(msg.severity).to.equal(2); 404 | expect(msg.message).to.equal('\'foo\' is never reassigned. Use \'const\' instead.'); 405 | expect(msg.line).to.equal(4); 406 | expect(msg.column).to.equal(5); 407 | expect(msg.nodeType).to.equal('Identifier'); 408 | }); 409 | 410 | it('enforces hapi/hapi-no-var', () => { 411 | 412 | const output = internals.lintFile('fixtures/no-var.js'); 413 | const results = output.results[0]; 414 | 415 | expect(output.errorCount).to.equal(1); 416 | expect(output.warningCount).to.equal(0); 417 | expect(results.errorCount).to.equal(1); 418 | expect(results.warningCount).to.equal(0); 419 | 420 | const msg = results.messages[0]; 421 | 422 | expect(msg.ruleId).to.equal('@hapi/hapi/no-var'); 423 | expect(msg.severity).to.equal(2); 424 | expect(msg.message).to.equal('Unexpected var, use let or const instead.'); 425 | expect(msg.line).to.equal(4); 426 | expect(msg.column).to.equal(1); 427 | expect(msg.nodeType).to.equal('VariableDeclaration'); 428 | }); 429 | 430 | it('enforces arrow-parens', () => { 431 | 432 | const output = internals.lintFile('fixtures/arrow-parens.js'); 433 | const results = output.results[0]; 434 | 435 | expect(output.errorCount).to.equal(1); 436 | expect(output.warningCount).to.equal(0); 437 | expect(results.errorCount).to.equal(1); 438 | expect(results.warningCount).to.equal(0); 439 | 440 | const msg = results.messages[0]; 441 | 442 | expect(msg.ruleId).to.equal('arrow-parens'); 443 | expect(msg.severity).to.equal(2); 444 | expect(msg.message).to.equal('Expected parentheses around arrow function argument.'); 445 | expect(msg.line).to.equal(2); 446 | expect(msg.column).to.equal(13); 447 | expect(msg.nodeType).to.equal('ArrowFunctionExpression'); 448 | }); 449 | 450 | it('enforces arrow-spacing', () => { 451 | 452 | const output = internals.lintFile('fixtures/arrow-spacing.js'); 453 | const results = output.results[0]; 454 | 455 | expect(output.errorCount).to.equal(2); 456 | expect(output.warningCount).to.equal(0); 457 | expect(results.errorCount).to.equal(2); 458 | expect(results.warningCount).to.equal(0); 459 | 460 | let msg = results.messages[0]; 461 | expect(msg.ruleId).to.equal('arrow-spacing'); 462 | expect(msg.severity).to.equal(2); 463 | expect(msg.message).to.equal('Missing space before =>.'); 464 | expect(msg.line).to.equal(2); 465 | expect(msg.column).to.equal(17); 466 | expect(msg.nodeType).to.equal('Punctuator'); 467 | 468 | msg = results.messages[1]; 469 | expect(msg.ruleId).to.equal('arrow-spacing'); 470 | expect(msg.severity).to.equal(2); 471 | expect(msg.message).to.equal('Missing space after =>.'); 472 | expect(msg.line).to.equal(7); 473 | expect(msg.column).to.equal(22); 474 | expect(msg.nodeType).to.equal('Punctuator'); 475 | }); 476 | 477 | it('enforces object-shorthand', () => { 478 | 479 | const output = internals.lintFile('fixtures/object-shorthand.js'); 480 | const results = output.results[0]; 481 | 482 | expect(output.errorCount).to.equal(1); 483 | expect(output.warningCount).to.equal(0); 484 | expect(results.errorCount).to.equal(1); 485 | expect(results.warningCount).to.equal(0); 486 | 487 | const msg = results.messages[0]; 488 | 489 | expect(msg.ruleId).to.equal('object-shorthand'); 490 | expect(msg.severity).to.equal(2); 491 | expect(msg.message).to.equal('Expected property shorthand.'); 492 | expect(msg.line).to.equal(10); 493 | expect(msg.column).to.equal(5); 494 | expect(msg.nodeType).to.equal('Property'); 495 | }); 496 | 497 | it('enforces prefer-arrow-callback', () => { 498 | 499 | const output = internals.lintFile('fixtures/prefer-arrow-callback.js'); 500 | const results = output.results[0]; 501 | 502 | expect(output.errorCount).to.equal(1); 503 | expect(output.warningCount).to.equal(0); 504 | expect(results.errorCount).to.equal(1); 505 | expect(results.warningCount).to.equal(0); 506 | 507 | const msg = results.messages[0]; 508 | 509 | expect(msg.ruleId).to.equal('prefer-arrow-callback'); 510 | expect(msg.severity).to.equal(2); 511 | expect(msg.message).to.equal('Unexpected function expression.'); 512 | expect(msg.line).to.equal(22); 513 | expect(msg.column).to.equal(8); 514 | expect(msg.nodeType).to.equal('FunctionExpression'); 515 | }); 516 | 517 | it('enforces no-constant-condition rule', () => { 518 | 519 | const output = internals.lintFile('fixtures/no-constant-condition.js'); 520 | const results = output.results[0]; 521 | 522 | expect(output.errorCount).to.equal(1); 523 | expect(output.warningCount).to.equal(0); 524 | expect(results.errorCount).to.equal(1); 525 | expect(results.warningCount).to.equal(0); 526 | 527 | const msg = results.messages[0]; 528 | 529 | expect(msg.ruleId).to.equal('no-constant-condition'); 530 | expect(msg.severity).to.equal(2); 531 | expect(msg.message).to.equal('Unexpected constant condition.'); 532 | expect(msg.line).to.equal(4); 533 | expect(msg.column).to.equal(5); 534 | expect(msg.nodeType).to.equal('ArrowFunctionExpression'); 535 | }); 536 | 537 | it('enforces no-unsafe-finally rule', () => { 538 | 539 | const output = internals.lintFile('fixtures/no-unsafe-finally.js'); 540 | const results = output.results[0]; 541 | 542 | expect(output.errorCount).to.equal(1); 543 | expect(output.warningCount).to.equal(0); 544 | expect(results.errorCount).to.equal(1); 545 | expect(results.warningCount).to.equal(0); 546 | 547 | const msg = results.messages[0]; 548 | 549 | expect(msg.ruleId).to.equal('no-unsafe-finally'); 550 | expect(msg.severity).to.equal(2); 551 | expect(msg.message).to.equal('Unsafe usage of ReturnStatement.'); 552 | expect(msg.line).to.equal(12); 553 | expect(msg.column).to.equal(9); 554 | expect(msg.nodeType).to.equal('ReturnStatement'); 555 | }); 556 | 557 | it('enforces no-useless-computed-key rule', () => { 558 | 559 | const output = internals.lintFile('fixtures/no-useless-computed-key.js'); 560 | const results = output.results[0]; 561 | 562 | expect(output.errorCount).to.equal(5); 563 | expect(output.warningCount).to.equal(0); 564 | expect(results.errorCount).to.equal(5); 565 | expect(results.warningCount).to.equal(0); 566 | 567 | let msg = results.messages[0]; 568 | 569 | expect(msg.ruleId).to.equal('no-useless-computed-key'); 570 | expect(msg.severity).to.equal(2); 571 | expect(msg.message).to.equal('Unnecessarily computed property [\'0\'] found.'); 572 | expect(msg.line).to.equal(2); 573 | expect(msg.column).to.equal(22); 574 | expect(msg.nodeType).to.equal('Property'); 575 | 576 | msg = results.messages[1]; 577 | 578 | expect(msg.ruleId).to.equal('no-useless-computed-key'); 579 | expect(msg.severity).to.equal(2); 580 | expect(msg.message).to.equal('Unnecessarily computed property [\'0+1,234\'] found.'); 581 | expect(msg.line).to.equal(3); 582 | expect(msg.column).to.equal(22); 583 | expect(msg.nodeType).to.equal('Property'); 584 | 585 | msg = results.messages[2]; 586 | 587 | expect(msg.ruleId).to.equal('no-useless-computed-key'); 588 | expect(msg.severity).to.equal(2); 589 | expect(msg.message).to.equal('Unnecessarily computed property [0] found.'); 590 | expect(msg.line).to.equal(4); 591 | expect(msg.column).to.equal(22); 592 | expect(msg.nodeType).to.equal('Property'); 593 | 594 | msg = results.messages[3]; 595 | 596 | expect(msg.ruleId).to.equal('no-useless-computed-key'); 597 | expect(msg.severity).to.equal(2); 598 | expect(msg.message).to.equal('Unnecessarily computed property [\'x\'] found.'); 599 | expect(msg.line).to.equal(5); 600 | expect(msg.column).to.equal(22); 601 | expect(msg.nodeType).to.equal('Property'); 602 | 603 | msg = results.messages[4]; 604 | 605 | expect(msg.ruleId).to.equal('no-useless-computed-key'); 606 | expect(msg.severity).to.equal(2); 607 | expect(msg.message).to.equal('Unnecessarily computed property [\'x\'] found.'); 608 | expect(msg.line).to.equal(6); 609 | expect(msg.column).to.equal(22); 610 | expect(msg.nodeType).to.equal('Property'); 611 | }); 612 | 613 | it('enforces handle-callback-err rule', () => { 614 | 615 | const output = internals.lintFile('fixtures/handle-callback-err.js'); 616 | const results = output.results[0]; 617 | 618 | expect(output.errorCount).to.equal(2); 619 | expect(output.warningCount).to.equal(0); 620 | expect(results.errorCount).to.equal(2); 621 | expect(results.warningCount).to.equal(0); 622 | 623 | let msg = results.messages[0]; 624 | 625 | expect(msg.ruleId).to.equal('handle-callback-err'); 626 | expect(msg.severity).to.equal(2); 627 | expect(msg.message).to.equal('Expected error to be handled.'); 628 | expect(msg.line).to.equal(6); 629 | expect(msg.column).to.equal(17); 630 | expect(msg.nodeType).to.equal('FunctionExpression'); 631 | 632 | msg = results.messages[1]; 633 | 634 | expect(msg.ruleId).to.equal('handle-callback-err'); 635 | expect(msg.severity).to.equal(2); 636 | expect(msg.message).to.equal('Expected error to be handled.'); 637 | expect(msg.line).to.equal(8); 638 | expect(msg.column).to.equal(23); 639 | expect(msg.nodeType).to.equal('FunctionExpression'); 640 | }); 641 | 642 | it('enforces no-dupe-keys rule', () => { 643 | 644 | const output = internals.lintFile('fixtures/no-dupe-keys.js'); 645 | const results = output.results[0]; 646 | 647 | expect(output.errorCount).to.equal(1); 648 | expect(output.warningCount).to.equal(0); 649 | expect(results.errorCount).to.equal(1); 650 | expect(results.warningCount).to.equal(0); 651 | 652 | const msg = results.messages[0]; 653 | 654 | expect(msg.ruleId).to.equal('no-dupe-keys'); 655 | expect(msg.severity).to.equal(2); 656 | expect(msg.message).to.equal('Duplicate key \'a\'.'); 657 | expect(msg.line).to.equal(6); 658 | expect(msg.column).to.equal(5); 659 | expect(msg.nodeType).to.equal('ObjectExpression'); 660 | }); 661 | 662 | it('uses the node environment', () => { 663 | 664 | const output = internals.lintFile('fixtures/node-env.js'); 665 | const results = output.results[0]; 666 | 667 | expect(output.errorCount).to.equal(0); 668 | expect(output.warningCount).to.equal(0); 669 | expect(results.errorCount).to.equal(0); 670 | expect(results.warningCount).to.equal(0); 671 | expect(results.messages).to.equal([]); 672 | }); 673 | 674 | it('uses the ES6 environment', () => { 675 | 676 | const output = internals.lintFile('fixtures/es6-env.js'); 677 | const results = output.results[0]; 678 | 679 | expect(output.errorCount).to.equal(0); 680 | expect(output.warningCount).to.equal(0); 681 | expect(results.errorCount).to.equal(0); 682 | expect(results.warningCount).to.equal(0); 683 | expect(results.messages).to.equal([]); 684 | }); 685 | 686 | it('does not enforce the camelcase lint rule', () => { 687 | 688 | const output = internals.lintFile('fixtures/camelcase.js'); 689 | const results = output.results[0]; 690 | 691 | expect(output.errorCount).to.equal(0); 692 | expect(output.warningCount).to.equal(0); 693 | expect(results.errorCount).to.equal(0); 694 | expect(results.warningCount).to.equal(0); 695 | expect(results.messages).to.equal([]); 696 | }); 697 | 698 | it('enforces key-spacing', () => { 699 | 700 | const output = internals.lintFile('fixtures/key-spacing.js'); 701 | const results = output.results[0]; 702 | 703 | expect(output.errorCount).to.equal(2); 704 | expect(output.warningCount).to.equal(0); 705 | expect(results.errorCount).to.equal(2); 706 | expect(results.warningCount).to.equal(0); 707 | }); 708 | 709 | it('enforces space-before-blocks', () => { 710 | 711 | const output = internals.lintFile('fixtures/space-before-blocks.js'); 712 | const results = output.results[0]; 713 | 714 | expect(output.errorCount).to.equal(2); 715 | expect(output.warningCount).to.equal(0); 716 | expect(results.errorCount).to.equal(2); 717 | expect(results.warningCount).to.equal(0); 718 | }); 719 | }); 720 | --------------------------------------------------------------------------------