├── .eslintrc.legacy.json ├── .gitattributes ├── .github ├── FUNDING.yml ├── codeql │ └── codeql-config.yml ├── dependabot.yml └── workflows │ ├── build.yml │ ├── codeql.yml │ ├── dependabot.yml │ ├── eslint.yml │ ├── release.yml │ ├── ship.yml │ ├── test-pr.yml │ └── test.yml ├── .gitignore ├── .husky ├── post-checkout ├── post-merge ├── post-rewrite └── pre-commit ├── .npmignore ├── .nvmrc ├── .prettierignore ├── .prettierrc.json ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── action.yml ├── assets ├── fix-example-screenshot.jpg └── suggestion-example-screenshot.jpg ├── bundle ├── changeDirectory.d.ts ├── commit.d.ts ├── getESLint.d.ts ├── getESLintResults.d.ts ├── getIndexedModifiedLines.d.ts ├── getOctokit.d.ts ├── getPullRequestMetadata.d.ts ├── getPushMetadata.d.ts ├── index.d.ts ├── index.js ├── index.js.map ├── licenses.txt ├── package.json ├── pullRequest.d.ts ├── push.d.ts └── sourcemap-register.cjs ├── eslint.config.js ├── package.json ├── src ├── changeDirectory.ts ├── commit.ts ├── getESLint.ts ├── getESLintResults.ts ├── getIndexedModifiedLines.ts ├── getOctokit.ts ├── getPullRequestMetadata.ts ├── getPushMetadata.ts ├── index.ts ├── pullRequest.ts └── push.ts ├── tests └── javascript │ ├── fixes │ ├── arrow-body-style-always-correct.js │ ├── arrow-body-style-always-incorrect.js │ ├── arrow-body-style-asNeeded-requireReturnForObjectLiteralTrue-correct.js │ ├── arrow-body-style-asNeeded-requireReturnForObjectLiteralTrue-incorrect.js │ ├── arrow-body-style-correct.js │ ├── arrow-body-style-incorrect.js │ ├── arrow-body-style-never-correct.js │ ├── arrow-body-style-never-incorrect.js │ ├── capitalized-comments-always-correct.js │ ├── capitalized-comments-always-incorrect.js │ ├── capitalized-comments-blockIgnorePattern-correct.js │ ├── capitalized-comments-blockIgnorePattern-incorrect.js │ ├── capitalized-comments-correct.js │ ├── capitalized-comments-ignoreConsecutiveCommentsTrue-correct.js │ ├── capitalized-comments-ignoreConsecutiveCommentsTrue-incorrect.js │ ├── capitalized-comments-ignoreInlineCommentsTrue-correct.js │ ├── capitalized-comments-ignorePatternPragma-correct.js │ ├── capitalized-comments-incorrect.js │ ├── capitalized-comments-never-correct.js │ ├── capitalized-comments-never-incorrect.js │ ├── curly-correct.js │ ├── curly-incorrect.js │ ├── curly-multi-consistent-correct.js │ ├── curly-multi-consistent-incorrect.js │ ├── curly-multi-correct.js │ ├── curly-multi-incorrect.js │ ├── curly-multiLine-correct.js │ ├── curly-multiLine-incorrect.js │ ├── curly-multiOrNest-correct.js │ ├── curly-multiOrNest-incorrect.js │ ├── deprecated │ │ ├── array-bracket-newline-consistent.js │ │ ├── array-bracket-newline-minItems.js │ │ ├── array-bracket-newline-multilineTrue-minItems.js │ │ ├── array-bracket-newline-multilineTrue.js │ │ ├── array-bracket-newline-never.js │ │ ├── array-bracket-newline.js │ │ ├── array-bracket-spacing-always.js │ │ ├── array-bracket-spacing-arraysInArraysFalse.js │ │ ├── array-bracket-spacing-objectsInArraysFalse.js │ │ ├── array-bracket-spacing-singleValueFalse.js │ │ ├── array-bracket-spacing.js │ │ ├── array-element-newline-ArrayExpressionAlways-ArrayPatternNever.js │ │ ├── array-element-newline-consistent.js │ │ ├── array-element-newline-minItems.js │ │ ├── array-element-newline-multilineTrue-minItems.js │ │ ├── array-element-newline-multilineTrue.js │ │ ├── array-element-newline-never.js │ │ ├── array-element-newline.js │ │ ├── arrow-parens-asNeeded.js │ │ ├── arrow-parens-requireForBlockBodyTrue.js │ │ ├── arrow-parens.js │ │ ├── arrow-spacing-beforeFalse-afterFalse.js │ │ ├── arrow-spacing-beforeFalse-afterTrue.js │ │ ├── arrow-spacing.js │ │ ├── block-spacing-never.js │ │ ├── block-spacing.js │ │ ├── brace-style-allman-allowSingleLineTrue.js │ │ ├── brace-style-allman.js │ │ ├── brace-style-allowSingleLineTrue.js │ │ ├── brace-style-stroustrup-allowSingleLineTrue.js │ │ ├── brace-style-stroustrup.js │ │ ├── brace-style.js │ │ ├── comma-dangle-always.js │ │ ├── comma-dangle-alwaysMultiline.js │ │ ├── comma-dangle-functionsAlways.js │ │ ├── comma-dangle-functionsNever.js │ │ ├── comma-dangle-onlyMultiline.js │ │ ├── comma-dangle.js │ │ ├── comma-spacing-beforeTrue-afterFalse.js │ │ ├── comma-spacing.js │ │ ├── comma-style-exceptions.js │ │ ├── comma-style-first.js │ │ ├── comma-style.js │ │ ├── computed-property-spacing-always.js │ │ ├── computed-property-spacing-enforceForClassMembersTrue.js │ │ ├── computed-property-spacing-never-enforceForClassMembersFalse.js │ │ ├── computed-property-spacing.js │ │ ├── multiline-comment-style-bareBlock.js │ │ ├── multiline-comment-style-separateLines.js │ │ ├── multiline-comment-style.js │ │ ├── no-confusing-arrow-allowParensFalse.js │ │ ├── no-confusing-arrow-onlyOneSimpleParamTrue.js │ │ ├── no-confusing-arrow.js │ │ ├── no-extra-semi.js │ │ ├── no-floating-decimal.js │ │ ├── one-var-declaration-per-line-always.js │ │ ├── one-var-declaration-per-line.js │ │ ├── quote-props-asNeeded-keywordsTrue.js │ │ ├── quote-props-asNeeded-numbersTrue.js │ │ ├── quote-props-asNeeded-unnecessaryFalse.js │ │ ├── quote-props-asNeeded.js │ │ ├── quote-props-consistent.js │ │ ├── quote-props-consistentAsNeeded-keywordsTrue.js │ │ ├── quote-props-consistentAsNeeded.js │ │ ├── quote-props.js │ │ ├── spaced-comment-always-marker.js │ │ ├── spaced-comment-exception.js │ │ ├── spaced-comment-never-marker.js │ │ ├── spaced-comment-never.js │ │ └── spaced-comment.js │ ├── dot-notation-allowKeywordsFalse-correct.js │ ├── dot-notation-allowPattern-correct.js │ ├── dot-notation-allowPattern-incorrect.js │ ├── dot-notation-correct.js │ ├── dot-notation-incorrect.js │ ├── eqeqeq-always-correct.js │ ├── eqeqeq-always-incorrect.js │ ├── eqeqeq-incorrect.js │ ├── eqeqeq-smart-correct.js │ ├── eqeqeq-smart-incorrect.js │ ├── logical-assignment-operators-correct.js │ ├── logical-assignment-operators-enforceForIfStatementsTrue-correct.js │ ├── logical-assignment-operators-enforceForIfStatementsTrue-incorrect.js │ ├── logical-assignment-operators-incorrect.js │ ├── logical-assignment-operators-never-correct.js │ ├── logical-assignment-operators-never-incorrect.js │ ├── no-div-regex-correct.js │ ├── no-div-regex-incorrect.js │ ├── no-else-return-allowElseIfFalse-correct.js │ ├── no-else-return-allowElseIfFalse-incorrect.js │ ├── no-else-return-correct.js │ ├── no-else-return-incorrect.js │ ├── no-extra-bind-correct.js │ ├── no-extra-bind-incorrect.js │ ├── no-extra-boolean-cast-correct.js │ ├── no-extra-boolean-cast-enforceForLogicalOperandsTrue-correct.js │ ├── no-extra-boolean-cast-enforceForLogicalOperandsTrue-incorrect.js │ ├── no-extra-boolean-cast-incorrect.js │ ├── no-extra-label-correct.js │ ├── no-extra-label-incorrect.js │ ├── no-implicit-coercion-allow-correct.js │ ├── no-implicit-coercion-boolean-correct.js │ ├── no-implicit-coercion-boolean-incorrect.js │ ├── no-implicit-coercion-disallowTemplateShorthandFalse-correct.js │ ├── no-implicit-coercion-disallowTemplateShorthandTrue-correct.js │ ├── no-implicit-coercion-disallowTemplateShorthandTrue-incorrect.js │ ├── no-implicit-coercion-number-correct.js │ ├── no-implicit-coercion-number-incorrect.js │ ├── no-implicit-coercion-string-correct.js │ ├── no-implicit-coercion-string-incorrect.js │ ├── no-lonely-if-correct.js │ ├── no-lonely-if-incorrect.js │ ├── no-regex-spaces-correct.js │ ├── no-regex-spaces-incorrect.js │ ├── no-undef-init-correct.js │ ├── no-undef-init-incorrect.js │ ├── no-unneeded-ternary-correct.js │ ├── no-unneeded-ternary-defaultAssignmentFalse-incorrect.js │ ├── no-unneeded-ternary-incorrect.js │ ├── no-unused-labels-correct.js │ ├── no-unused-labels-incorrect.js │ ├── no-useless-computed-key-correct.js │ ├── no-useless-computed-key-enforceForClassMembersFalse-correct.js │ ├── no-useless-computed-key-enforceForClassMembersFalse-incorrect.js │ ├── no-useless-computed-key-incorrect.js │ ├── no-useless-rename-correct.js │ ├── no-useless-rename-ignoreDestructuringTrue-correct.js │ ├── no-useless-rename-ignoreExportTrue-correct.js │ ├── no-useless-rename-ignoreImportTrue-correct.js │ ├── no-useless-rename-incorrect.js │ ├── no-useless-return-correct.js │ ├── no-useless-return-incorrect.js │ ├── no-var-correct.js │ ├── no-var-incorrect.js │ ├── object-shorthand-avoidExplicitReturnArrowsTrue-correct.js │ ├── object-shorthand-avoidExplicitReturnArrowsTrue-incorrect.js │ ├── object-shorthand-avoidQuotesTrue-correct.js │ ├── object-shorthand-avoidQuotesTrue-incorrect.js │ ├── object-shorthand-consistent-correct.js │ ├── object-shorthand-consistent-incorrect.js │ ├── object-shorthand-consistentAsNeeded-incorrect.js │ ├── object-shorthand-ignoreConstructorsTrue-correct.js │ ├── object-shorthand-methodsIgnorePattern-correct.js │ ├── one-var-consecutive-correct.js │ ├── one-var-consecutive-incorrect.js │ ├── one-var-correct.js │ ├── one-var-incorrect.js │ ├── one-var-initializedAlways-uninitializedNever-correct.js │ ├── one-var-initializedAlways-uninitializedNever-incorrect.js │ ├── one-var-initializedConsecutive-correct.js │ ├── one-var-initializedConsecutive-incorrect.js │ ├── one-var-initializedConsecutive-uninitializedNever-correct.js │ ├── one-var-initializedConsecutive-uninitializedNever-incorrect.js │ ├── one-var-initializedNever-correct.js │ ├── one-var-initializedNever-incorrect.js │ ├── one-var-never-correct.js │ ├── one-var-never-incorrect.js │ ├── one-var-separateRequiresTrue-varAlways-correct-1.js │ ├── one-var-separateRequiresTrue-varAlways-correct-2.js │ ├── one-var-separateRequiresTrue-varAlways-incorrect.js │ ├── one-var-varAlways-letNever-constNever-correct.js │ ├── one-var-varAlways-letNever-constNever-incorrect.js │ ├── one-var-varConsecutive-correct.js │ ├── one-var-varConsecutive-incorrect.js │ ├── one-var-varNever-correct.js │ ├── one-var-varNever-incorrect.js │ ├── one-var-varNever-letConsecutive-constConsecutive-correct.js │ ├── one-var-varNever-letConsecutive-constConsecutive-incorrect.js │ ├── operator-assignment-correct.js │ ├── operator-assignment-incorrect.js │ ├── operator-assignment-never-correct.js │ ├── operator-assignment-never-incorrect.js │ ├── prefer-arrow-callback-allowNamedFunctionsTrue-correct.js │ ├── prefer-arrow-callback-allowUnboundThisFalse-incorrect.js │ ├── prefer-arrow-callback-correct.js │ ├── prefer-arrow-callback-incorrect.js │ ├── prefer-const-correct.js │ ├── prefer-const-destructuringAll-correct.js │ ├── prefer-const-destructuringAll-incorrect.js │ ├── prefer-const-destructuringAny-correct.js │ ├── prefer-const-destructuringAny-incorrect.js │ ├── prefer-const-ignoreReadBeforeAssignFalse-correct.js │ ├── prefer-const-ignoreReadBeforeAssignTrue-correct.js │ ├── prefer-const-incorrect.js │ ├── prefer-destructuring-AssignmentExpressionArrayTrue-correct.js │ ├── prefer-destructuring-VariableDeclaratorObjectTrue-correct.js │ ├── prefer-destructuring-correct.js │ ├── prefer-destructuring-enforceForRenamedPropertiesTrue-correct-1.js │ ├── prefer-destructuring-enforceForRenamedPropertiesTrue-correct-2.js │ ├── prefer-destructuring-enforceForRenamedPropertiesTrue-incorrect.js │ ├── prefer-destructuring-incorrect.js │ ├── prefer-exponentiation-operator-correct.js │ ├── prefer-exponentiation-operator-incorrect.js │ ├── prefer-numeric-literals-correct.js │ ├── prefer-numeric-literals-incorrect.js │ ├── prefer-object-has-own-correct.js │ ├── prefer-object-has-own-incorrect.js │ ├── prefer-object-spread-correct.js │ ├── prefer-object-spread-incorrect.js │ ├── prefer-template-correct.js │ ├── prefer-template-incorrect.js │ ├── sort-imports-allowSeparatedGroupsTrue-correct-1.js │ ├── sort-imports-allowSeparatedGroupsTrue-correct-2.js │ ├── sort-imports-allowSeparatedGroupsTrue-correct-3.js │ ├── sort-imports-allowSeparatedGroupsTrue-incorrect.js │ ├── sort-imports-correct-1.js │ ├── sort-imports-correct-2.js │ ├── sort-imports-correct-3.js │ ├── sort-imports-correct-4.js │ ├── sort-imports-ignoreCaseFalse-correct.js │ ├── sort-imports-ignoreCaseFalse-incorrect.js │ ├── sort-imports-ignoreCaseTrue-correct.js │ ├── sort-imports-ignoreCaseTrue-incorrect.js │ ├── sort-imports-ignoreDeclarationSortFalse-correct.js │ ├── sort-imports-ignoreDeclarationSortFalse-incorrect.js │ ├── sort-imports-ignoreDeclarationSortTrue-correct.js │ ├── sort-imports-ignoreDeclarationSortTrue-incorrect.js │ ├── sort-imports-ignoreMemberSortFalse-correct.js │ ├── sort-imports-ignoreMemberSortFalse-incorrect.js │ ├── sort-imports-ignoreMemberSortTrue-correct.js │ ├── sort-imports-ignoreMemberSortTrue-incorrect.js │ ├── sort-imports-incorrect-1.js │ ├── sort-imports-incorrect-2.js │ ├── sort-imports-incorrect-3.js │ ├── sort-imports-incorrect-4.js │ ├── sort-imports-incorrect-5.js │ ├── sort-imports-incorrect-6.js │ ├── sort-imports-incorrect-7.js │ ├── sort-imports-memberSyntaxSortOrderAllSingleMultipleNone-correct.js │ ├── sort-imports-memberSyntaxSortOrderNoneAllMultipleSingle-incorrect.js │ ├── sort-imports-memberSyntaxSortOrderSingleAllMultipleNone-correct.js │ ├── sort-vars-correct.js │ ├── sort-vars-ignoreCaseTrue-correct.js │ ├── sort-vars-incorrect.js │ ├── yoda-always-correct.js │ ├── yoda-always-incorrect.js │ ├── yoda-correct.js │ ├── yoda-exceptRangeTrue-correct.js │ ├── yoda-incorrect.js │ └── yoda-onlyEqualityTrue-correct.js │ └── suggestions │ ├── array-callback-return-allowImplicitTrue-correct.js │ ├── array-callback-return-allowVoidTrue-correct.js │ ├── array-callback-return-checkForEachTrue-correct.js │ ├── array-callback-return-checkForEachTrue-incorrect.js │ ├── array-callback-return-correct.js │ ├── array-callback-return-incorrect.js │ ├── no-array-constructor-correct.js │ ├── no-array-constructor-incorrect.js │ ├── no-case-declarations-correct.js │ ├── no-case-declarations-incorrect.js │ ├── no-console-allowWarnError-correct.js │ ├── no-console-correct.js │ ├── no-console-incorrect.js │ ├── no-empty-allowEmptyCatchTrue-correct.js │ ├── no-empty-correct.js │ ├── no-empty-incorrect.js │ ├── no-implicit-coercion-allow-correct.js │ ├── no-implicit-coercion-boolean-correct.js │ ├── no-implicit-coercion-boolean-incorrect.js │ ├── no-implicit-coercion-disallowTemplateShorthandFalse-correct.js │ ├── no-implicit-coercion-disallowTemplateShorthandTrue-correct.js │ ├── no-implicit-coercion-disallowTemplateShorthandTrue-incorrect.js │ ├── no-implicit-coercion-number-correct.js │ ├── no-implicit-coercion-number-incorrect.js │ ├── no-implicit-coercion-string-correct.js │ ├── no-implicit-coercion-string-incorrect.js │ ├── no-misleading-character-class-correct.js │ ├── no-misleading-character-class-incorrect.js │ ├── no-nonoctal-decimal-escape-correct.js │ ├── no-nonoctal-decimal-escape-incorrect.js │ ├── no-object-constructor-correct.js │ ├── no-object-constructor-incorrect.js │ ├── no-promise-executor-return-allowVoidTrue-correct.js │ ├── no-promise-executor-return-correct.js │ ├── no-promise-executor-return-incorrect.js │ ├── no-prototype-builtins-correct.js │ ├── no-prototype-builtins-incorrect.js │ ├── no-unsafe-negation-correct.js │ ├── no-unsafe-negation-enforceForOrderingRelationsTrue-incorrect.js │ ├── no-unsafe-negation-exception-correct.js │ ├── no-unsafe-negation-exception-incorrect.js │ ├── no-unsafe-negation-incorrect.js │ ├── no-useless-escape-correct.js │ ├── no-useless-escape-incorrect.js │ ├── prefer-named-capture-group-correct.js │ ├── prefer-named-capture-group-incorrect.js │ ├── prefer-regex-literals-correct.js │ ├── prefer-regex-literals-disallowRedundantWrappingTrue-correct.js │ ├── prefer-regex-literals-disallowRedundantWrappingTrue-incorrect.js │ ├── prefer-regex-literals-incorrect.js │ ├── radix-asNeeded-correct.js │ ├── radix-asNeeded-incorrect.js │ ├── radix-correct.js │ ├── radix-incorrect.js │ ├── require-unicode-regexp-correct.js │ ├── require-unicode-regexp-incorrect.js │ ├── use-isnan-correct.js │ ├── use-isnan-enforceForIndexOfTrue-correct.js │ ├── use-isnan-enforceForIndexOfTrue-incorrect.js │ ├── use-isnan-enforceForSwitchCaseFalse-correct.js │ ├── use-isnan-enforceForSwitchCaseTrue-correct.js │ ├── use-isnan-enforceForSwitchCaseTrue-incorrect.js │ ├── use-isnan-incorrect.js │ ├── valid-typeof-correct.js │ ├── valid-typeof-incorrect.js │ ├── valid-typeof-requireStringLiteralsTrue-correct.js │ └── valid-typeof-requireStringLiteralsTrue-incorrect.js ├── tsconfig.json └── yarn.lock /.eslintrc.legacy.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | "node": true 6 | }, 7 | "extends": ["eslint:recommended", "plugin:prettier/recommended"], 8 | "parserOptions": { 9 | "ecmaVersion": "latest", 10 | "sourceType": "module" 11 | }, 12 | "plugins": ["@typescript-eslint"], 13 | "root": true, 14 | "rules": {}, 15 | "ignorePatterns": ["node_modules/**/*", "lib/**/*", "dist/**/*"], 16 | "overrides": [ 17 | { 18 | "files": ["*.ts"], 19 | "extends": ["plugin:@typescript-eslint/recommended"], 20 | "parser": "@typescript-eslint/parser", 21 | "parserOptions": { 22 | "project": "./tsconfig.json" 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | dist/**/* linguist-generated 2 | bundle/**/* linguist-generated 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: CatChen 2 | patreon: catchen 3 | custom: ['https://www.buymeacoffee.com/catchen'] 4 | -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | paths-ignore: 2 | - dist/ 3 | - bundle/ 4 | - node_modules/ 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: '/' 5 | schedule: 6 | interval: daily 7 | ignore: 8 | - dependency-name: '@vercel/ncc' 9 | versions: ['0.38.*'] 10 | groups: 11 | types: 12 | patterns: 13 | - '@types/*' 14 | development-dependencies: 15 | dependency-type: 'development' 16 | exclude-patterns: 17 | - '@types/*' 18 | actions: 19 | patterns: 20 | - '@actions/*' 21 | reviewers: 22 | - CatChen 23 | assignees: 24 | - CatChen 25 | labels: 26 | - accept2ship 27 | 28 | - package-ecosystem: 'github-actions' 29 | directory: '/' 30 | schedule: 31 | interval: daily 32 | assignees: 33 | - CatChen 34 | labels: 35 | - pass2ship 36 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main, '[0-9]+-[0-9]+-*'] 8 | workflow_run: 9 | workflows: ['Dependabot'] 10 | branches: ['dependabot/**/*'] 11 | types: 12 | - completed 13 | workflow_dispatch: 14 | workflow_call: 15 | 16 | jobs: 17 | build: 18 | name: Build 19 | if: ${{ !startsWith(github.head_ref || github.event.workflow_run.head_branch, 'workflows/tests/') }} 20 | runs-on: ubuntu-latest 21 | permissions: 22 | pull-requests: write 23 | contents: write 24 | steps: 25 | - uses: actions/create-github-app-token@v2 26 | id: get-github-app-token 27 | if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} 28 | with: 29 | app-id: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_ID }} 30 | private-key: ${{ secrets.CHECK_GIT_STATUS_BOT_APP_PRIVATE_KEY }} 31 | 32 | - uses: actions/checkout@v4 33 | with: 34 | repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} 35 | ref: ${{ github.head_ref }} 36 | token: ${{ steps.get-github-app-token.outputs.token || github.token }} 37 | 38 | - uses: actions/setup-node@v4 39 | with: 40 | node-version-file: '.nvmrc' 41 | check-latest: true 42 | cache: yarn 43 | 44 | - name: Install dependencies 45 | run: yarn 46 | 47 | - name: Reformat 48 | run: | 49 | yarn prettier --write . 50 | yarn lint --fix || true # Ignore errors and leave them to the ESLint workflow 51 | 52 | - name: Build 53 | run: yarn build 54 | 55 | - name: Bundle 56 | run: yarn bundle 57 | 58 | - uses: CatChen/check-git-status-action@v1 59 | id: check-git-status 60 | with: 61 | fail-if-not-clean: ${{ github.actor != 'dependabot[bot]' || github.actor_id != 49699333 }} 62 | push-if-not-clean: true 63 | request-changes-if-not-clean: false 64 | push-token: ${{ steps.get-github-app-token.outputs.token || github.token }} 65 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot 2 | 3 | on: 4 | pull_request: 5 | branches: [main] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | label: 10 | name: Label 11 | if: ${{ !startsWith(github.head_ref, 'workflows/tests/') && github.actor == 'dependabot[bot]' && github.actor_id == 49699333 }} 12 | permissions: 13 | pull-requests: write 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Dependabot metadata 17 | id: dependabot-metadata 18 | uses: dependabot/fetch-metadata@v2 19 | 20 | - name: Add label for types group 21 | if: ${{ steps.dependabot-metadata.outputs.dependency-group == 'types' }} 22 | env: 23 | GH_TOKEN: ${{ github.token }} 24 | REPO: ${{ github.repository }} 25 | PR_NUMBER: ${{ github.event.pull_request.number }} 26 | run: | 27 | gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "pass2ship" 28 | gh api \ 29 | --method DELETE \ 30 | -H "Accept: application/vnd.github+json" \ 31 | -H "X-GitHub-Api-Version: 2022-11-28" \ 32 | "/repos/$REPO/pulls/$PR_NUMBER/requested_reviewers" \ 33 | -f "reviewers[]=CatChen" 34 | 35 | - name: Add label for development-dependencies group 36 | if: ${{ steps.dependabot-metadata.outputs.dependency-group == 'development-dependencies' }} 37 | env: 38 | GH_TOKEN: ${{ github.token }} 39 | REPO: ${{ github.repository }} 40 | PR_NUMBER: ${{ github.event.pull_request.number }} 41 | run: | 42 | gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "pass2ship" 43 | gh api \ 44 | --method DELETE \ 45 | -H "Accept: application/vnd.github+json" \ 46 | -H "X-GitHub-Api-Version: 2022-11-28" \ 47 | "/repos/$REPO/pulls/$PR_NUMBER/requested_reviewers" \ 48 | -f "reviewers[]=CatChen" 49 | -------------------------------------------------------------------------------- /.github/workflows/eslint.yml: -------------------------------------------------------------------------------- 1 | name: ESLint 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main, '[0-9]+-[0-9]+-*'] 8 | workflow_run: 9 | workflows: ['Dependabot'] 10 | branches: ['dependabot/**/*'] 11 | types: 12 | - completed 13 | workflow_dispatch: 14 | workflow_call: 15 | 16 | jobs: 17 | eslint: 18 | name: ESLint 19 | if: ${{ !startsWith(github.head_ref || github.event.workflow_run.head_branch, 'workflows/tests/') }} 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - uses: actions/setup-node@v4 26 | with: 27 | node-version-file: '.nvmrc' 28 | check-latest: true 29 | cache: yarn 30 | 31 | - name: Install dependencies 32 | run: yarn install 33 | 34 | - uses: ./ 35 | env: 36 | DEBUG: 'eslint:cli-engine' 37 | with: 38 | targets: 'src' 39 | fail-check: ${{ github.event_name == 'workflow_call' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} 40 | -------------------------------------------------------------------------------- /.husky/post-checkout: -------------------------------------------------------------------------------- 1 | yarn install 2 | -------------------------------------------------------------------------------- /.husky/post-merge: -------------------------------------------------------------------------------- 1 | yarn install 2 | -------------------------------------------------------------------------------- /.husky/post-rewrite: -------------------------------------------------------------------------------- 1 | if test "$1" = "rebase"; then 2 | yarn install 3 | fi -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | yarn bundle 2 | git add bundle 3 | 4 | yarn lint-staged 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitattributes 2 | .github/ 3 | .husky/ 4 | .vscode/ 5 | .nvmrc 6 | .prettierignore 7 | .prettierrc.json 8 | action.yml 9 | assets/ 10 | bundle/ 11 | src/ 12 | tests/ 13 | eslint.config.js 14 | tsconfig.json 15 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | bundle/ 3 | tests/ 4 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "bracketSpacing": true, 4 | "bracketSameLine": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | "tabWidth": 2, 8 | "trailingComma": "all", 9 | "importOrder": [ 10 | "^@action/core/(.*)$", 11 | "^@action/github/(.*)$", 12 | "^@action/exec/(.*)$", 13 | "^@action/glob/(.*)$", 14 | "^@action/(.*)$", 15 | "", 16 | "^[./]" 17 | ], 18 | "importOrderSortIndividualImports": true, 19 | "importOrderMergeDuplicateImports": true, 20 | "importOrderBuiltinModulesToTop": true, 21 | "importOrderTypeImportsToTop": true, 22 | "plugins": ["@serverless-guru/prettier-plugin-import-order"] 23 | } 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "typescript.enablePromptUseWorkspaceTsdk": true, 4 | "yaml.schemas": { 5 | "https://json.schemastore.org/github-action.json": "action.yml", 6 | "https://json.schemastore.org/github-funding.json": ".github/FUNDING.yml", 7 | "https://json.schemastore.org/github-workflow.json": ".github/workflows/*.yml", 8 | "https://json.schemastore.org/package.json": "package.json", 9 | "https://json.schemastore.org/tsconfig.json": "tsconfig.json", 10 | "https://json.schemastore.org/eslintrc.json": ".eslintrc.json", 11 | "https://json.schemastore.org/prettierrc.json": ".prettierrc.json" 12 | }, 13 | "files.exclude": { 14 | "**/dist": true, 15 | "**/bundle": true, 16 | "**/node_modules": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Cat Chen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'ESLint Suggestion' 2 | description: 'Pull Request Suggestions from ESLint' 3 | inputs: 4 | request-changes: 5 | description: "Request changes if ESLint doesn't pass." 6 | required: false 7 | default: true 8 | fail-check: 9 | description: "Fail the workflow and its corresponding check if ESLint doesn't pass." 10 | required: false 11 | default: false 12 | github-token: 13 | description: 'GitHub token.' 14 | required: false 15 | default: ${{ github.token }} 16 | directory: 17 | description: "Directory to run ESLint if it's not the project's root directory." 18 | required: false 19 | default: './' 20 | targets: 21 | description: 'Files, directories, and/or globs to run ESLint.' 22 | required: false 23 | default: '.' 24 | eslint-lib-path: 25 | description: 'Path to the ESLint JavaScript library file.' 26 | required: false 27 | default: './node_modules/eslint/lib/api.js' 28 | eslint-bin-path: 29 | description: 'Path to the ESLint binary file.' 30 | required: false 31 | default: './node_modules/.bin/eslint' 32 | deprecationMessage: 'Use eslint-lib-path instead.' 33 | config-path: 34 | description: 'Path to the ESLint config file.' 35 | required: false 36 | runs: 37 | using: 'node20' 38 | main: 'bundle/index.js' 39 | branding: 40 | icon: 'plus-square' 41 | color: 'blue' 42 | -------------------------------------------------------------------------------- /assets/fix-example-screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatChen/eslint-suggestion-action/2e556332a04f774220708663f346a9e869901602/assets/fix-example-screenshot.jpg -------------------------------------------------------------------------------- /assets/suggestion-example-screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatChen/eslint-suggestion-action/2e556332a04f774220708663f346a9e869901602/assets/suggestion-example-screenshot.jpg -------------------------------------------------------------------------------- /bundle/changeDirectory.d.ts: -------------------------------------------------------------------------------- 1 | export declare function changeDirectory(): void; 2 | -------------------------------------------------------------------------------- /bundle/commit.d.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint, Rule } from 'eslint'; 2 | export declare function handleCommit(eventName: string, results: ESLint.LintResult[], ruleMetaDatas: { 3 | [name: string]: Rule.RuleMetaData; 4 | }): void; 5 | -------------------------------------------------------------------------------- /bundle/getESLint.d.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint as ProjectESLint } from 'eslint'; 2 | export declare function getESLint(): Promise; 3 | -------------------------------------------------------------------------------- /bundle/getESLintResults.d.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint } from 'eslint'; 2 | export declare function getESLintResults(eslint: ESLint): Promise; 3 | -------------------------------------------------------------------------------- /bundle/getIndexedModifiedLines.d.ts: -------------------------------------------------------------------------------- 1 | import type { components } from '@octokit/openapi-types/types.js'; 2 | export declare function getIndexedModifiedLines(file: components['schemas']['diff-entry']): { 3 | [line: string]: true; 4 | }; 5 | -------------------------------------------------------------------------------- /bundle/getOctokit.d.ts: -------------------------------------------------------------------------------- 1 | import { type Octokit } from '@octokit/core/dist-types/index.js'; 2 | import { type PaginateInterface } from '@octokit/plugin-paginate-rest'; 3 | import { type Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 4 | export declare function getOctokit(githubToken: string): Octokit & Api & { 5 | paginate: PaginateInterface; 6 | }; 7 | -------------------------------------------------------------------------------- /bundle/getPullRequestMetadata.d.ts: -------------------------------------------------------------------------------- 1 | import type { Octokit } from '@octokit/core'; 2 | import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 3 | export declare function getPullRequestMetadata(): { 4 | owner: string; 5 | repo: string; 6 | pullRequestNumber: number; 7 | baseSha: string; 8 | headSha: string; 9 | }; 10 | export declare function getPullRequestMetadataByNumber(octokit: Octokit & Api, pullRequestNumber: number): Promise<{ 11 | owner: string; 12 | repo: string; 13 | pullRequestNumber: number; 14 | baseSha: string; 15 | headSha: string; 16 | }>; 17 | -------------------------------------------------------------------------------- /bundle/getPushMetadata.d.ts: -------------------------------------------------------------------------------- 1 | export declare function getPushMetadata(): { 2 | owner: string; 3 | repo: string; 4 | beforeSha: string; 5 | afterSha: string; 6 | }; 7 | -------------------------------------------------------------------------------- /bundle/index.d.ts: -------------------------------------------------------------------------------- 1 | export declare function run(): Promise; 2 | -------------------------------------------------------------------------------- /bundle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /bundle/pullRequest.d.ts: -------------------------------------------------------------------------------- 1 | import type { Octokit } from '@octokit/core'; 2 | import type { components } from '@octokit/openapi-types/types.js'; 3 | import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 4 | import type { ESLint, Rule } from 'eslint'; 5 | type ReviewSuggestion = { 6 | start_side?: 'RIGHT'; 7 | start_line?: number; 8 | side: 'RIGHT'; 9 | line: number; 10 | body: string; 11 | }; 12 | type ReviewComment = ReviewSuggestion & { 13 | path: string; 14 | }; 15 | export declare function getCommentFromFix(source: string, line: number, fix: Rule.Fix): ReviewSuggestion; 16 | export declare function matchReviewComments(reviewComments: Pick[], reviewComment: ReviewComment): string[]; 17 | export declare function handlePullRequest(octokit: Octokit & Api, indexedResults: { 18 | [file: string]: ESLint.LintResult; 19 | }, ruleMetaDatas: { 20 | [name: string]: Rule.RuleMetaData; 21 | }, owner: string, repo: string, pullRequestNumber: number, baseSha: string, headSha: string): Promise; 22 | export {}; 23 | -------------------------------------------------------------------------------- /bundle/push.d.ts: -------------------------------------------------------------------------------- 1 | import type { Octokit } from '@octokit/core'; 2 | import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 3 | import type { ESLint, Rule } from 'eslint'; 4 | export declare function handlePush(octokit: Octokit & Api, indexedResults: { 5 | [file: string]: ESLint.LintResult; 6 | }, ruleMetaDatas: { 7 | [name: string]: Rule.RuleMetaData; 8 | }, owner: string, repo: string, beforeSha: string, afterSha: string): Promise; 9 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { fileURLToPath } from 'url'; 3 | import { FlatCompat } from '@eslint/eslintrc'; 4 | import js from '@eslint/js'; 5 | import ts from 'typescript-eslint'; 6 | 7 | const __filename = fileURLToPath(import.meta.url); 8 | const __dirname = path.dirname(__filename); 9 | 10 | const compat = new FlatCompat({ 11 | baseDirectory: __dirname, 12 | resolvePluginsRelativeTo: __dirname, 13 | recommendedConfig: js.configs.recommended, 14 | }); 15 | 16 | const jsConfigs = compat.config({ 17 | env: { 18 | browser: true, 19 | es2022: true, 20 | node: true, 21 | }, 22 | extends: ['eslint:recommended', 'plugin:prettier/recommended'], 23 | parserOptions: { 24 | ecmaVersion: 'latest', 25 | sourceType: 'module', 26 | }, 27 | root: true, 28 | rules: {}, 29 | ignorePatterns: [ 30 | 'tests/**/*', 31 | 'node_modules/**/*', 32 | 'dist/**/*', 33 | 'bundle/**/*', 34 | ], 35 | overrides: [ 36 | { 37 | files: ['**/*.js'], 38 | }, 39 | ], 40 | }); 41 | 42 | const tsConfigs = [ 43 | ...ts.configs.recommendedTypeChecked, 44 | { 45 | languageOptions: { 46 | parserOptions: { 47 | project: './tsconfig.json', 48 | }, 49 | }, 50 | }, 51 | ].map((config) => ({ 52 | ...config, 53 | files: ['src/**/*.ts'], 54 | })); 55 | 56 | const configs = ts.config(...jsConfigs, ...tsConfigs); 57 | 58 | export default configs; 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-suggestion-action", 3 | "version": "4.1.18", 4 | "description": "", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.js", 7 | "type": "module", 8 | "scripts": { 9 | "build": "rm -rf dist && yarn tsc", 10 | "bundle": "rm -rf bundle && yarn ncc build src/index.ts --external eslint --source-map --license licenses.txt --out bundle", 11 | "test": "echo \"Error: no test specified\" && exit 1", 12 | "lint": "eslint -c eslint.config.js", 13 | "prepublishOnly": "pinst --disable && yarn build", 14 | "postpublish": "pinst --enable", 15 | "preversion": "yarn && yarn build && yarn bundle", 16 | "prepare": "is-ci || husky" 17 | }, 18 | "devDependencies": { 19 | "@eslint/eslintrc": "^3.0.2", 20 | "@eslint/js": "^9.2.0", 21 | "@octokit/graphql-schema": "^15.3.0", 22 | "@octokit/webhooks-types": "^7.6.1", 23 | "@serverless-guru/prettier-plugin-import-order": "^0.4.1", 24 | "@types/eslint": "^9.6.0", 25 | "@types/glob": "^8.0.0", 26 | "@types/node": "^24.0.0", 27 | "@typescript-eslint/eslint-plugin": "^8.0.1", 28 | "@typescript-eslint/parser": "^8.0.1", 29 | "@vercel/ncc": "0.38.1", 30 | "eslint": "^9.0.0", 31 | "eslint-config-prettier": "^10.0.1", 32 | "eslint-plugin-prettier": "^5.0.0", 33 | "husky": "^9.0.5", 34 | "is-ci": "^4.1.0", 35 | "lint-staged": "^16.0.0", 36 | "pinst": "^3.0.0", 37 | "prettier": "^3.0.2", 38 | "typescript": "^5.0.2", 39 | "typescript-eslint": "^8.0.1" 40 | }, 41 | "repository": { 42 | "type": "git", 43 | "url": "git+https://github.com/CatChen/eslint-suggestion-action.git" 44 | }, 45 | "author": "Cat Chen", 46 | "license": "MIT", 47 | "bugs": { 48 | "url": "https://github.com/CatChen/eslint-suggestion-action/issues" 49 | }, 50 | "homepage": "https://github.com/CatChen/eslint-suggestion-action#readme", 51 | "funding": "https://github.com/CatChen/eslint-suggestion-action?sponsor=1", 52 | "dependencies": { 53 | "@actions/core": "^1.10.0", 54 | "@actions/exec": "^1.1.1", 55 | "@actions/github": "^6.0.0", 56 | "@octokit/plugin-retry": "^8.0.1", 57 | "@octokit/plugin-throttling": "^11.0.1", 58 | "glob": "^11.0.0" 59 | }, 60 | "resolutions": { 61 | "strip-ansi": "6.0.1" 62 | }, 63 | "lint-staged": { 64 | "*.(ts,js)": "yarn lint --fix", 65 | "*.json": "yarn prettier -w", 66 | "*.(yml,yaml)": "yarn prettier -w", 67 | "*.(md,markdown)": "yarn prettier -w" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/changeDirectory.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import { chdir, cwd } from 'node:process'; 3 | import { getInput, info } from '@actions/core'; 4 | 5 | const DEFAULT_WORKING_DIRECTORY = cwd(); 6 | 7 | export function changeDirectory() { 8 | info(`Working directory is: ${DEFAULT_WORKING_DIRECTORY}`); 9 | const absoluteDirectory = path.resolve( 10 | DEFAULT_WORKING_DIRECTORY, 11 | getInput('directory'), 12 | ); 13 | if (absoluteDirectory !== DEFAULT_WORKING_DIRECTORY) { 14 | info(`Working directory is changed to: ${absoluteDirectory}`); 15 | chdir(absoluteDirectory); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/commit.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint, Rule } from 'eslint'; 2 | import path from 'node:path'; 3 | import { cwd } from 'node:process'; 4 | import { 5 | endGroup, 6 | error, 7 | getBooleanInput, 8 | info, 9 | notice, 10 | startGroup, 11 | warning, 12 | } from '@actions/core'; 13 | 14 | export function handleCommit( 15 | eventName: string, 16 | results: ESLint.LintResult[], 17 | ruleMetaDatas: { 18 | [name: string]: Rule.RuleMetaData; 19 | }, 20 | ) { 21 | const failCheck = getBooleanInput('fail-check'); 22 | 23 | startGroup(`GitHub ${eventName}`); 24 | let warningCounter = 0; 25 | let errorCounter = 0; 26 | 27 | for (const result of results) { 28 | const relativePath = path.relative(cwd(), result.filePath); 29 | for (const message of result.messages) { 30 | if (message.ruleId === null || result.source === undefined) { 31 | continue; 32 | } 33 | const rule = ruleMetaDatas[message.ruleId]; 34 | info(` ${relativePath}:${message.line}`); 35 | switch (message.severity) { 36 | case 1: 37 | warning( 38 | `[${message.ruleId}]${message.message}: (${rule?.docs?.url})`, 39 | { 40 | file: relativePath, 41 | startLine: message.line, 42 | }, 43 | ); 44 | warningCounter++; 45 | break; 46 | case 2: 47 | error(`[${message.ruleId}]${message.message}: (${rule?.docs?.url})`, { 48 | file: relativePath, 49 | startLine: message.line, 50 | }); 51 | errorCounter++; 52 | break; 53 | } 54 | } 55 | } 56 | endGroup(); 57 | 58 | startGroup('Feedback'); 59 | if (warningCounter > 0 || errorCounter > 0) { 60 | if (failCheck) { 61 | throw new Error('ESLint fails.'); 62 | } else { 63 | error('ESLint fails'); 64 | } 65 | } else { 66 | notice('ESLint passes'); 67 | } 68 | endGroup(); 69 | } 70 | -------------------------------------------------------------------------------- /src/getESLint.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint as ProjectESLint, Linter as ProjectLinter } from 'eslint'; 2 | import { existsSync } from 'node:fs'; 3 | import { createRequire } from 'node:module'; 4 | import { resolve } from 'node:path'; 5 | import { cwd } from 'node:process'; 6 | import { getInput, notice } from '@actions/core'; 7 | 8 | export async function getESLint() { 9 | const absoluteDirectory = cwd(); 10 | const require = createRequire(absoluteDirectory); 11 | const eslintJsPath = resolve(absoluteDirectory, getInput('eslint-lib-path')); 12 | if (!existsSync(eslintJsPath)) { 13 | throw new Error(`ESLint JavaScript cannot be found at ${eslintJsPath}`); 14 | } 15 | notice(`Using ESLint from: ${eslintJsPath}`); 16 | const { ESLint, loadESLint } = require(eslintJsPath) as { 17 | ESLint: typeof ProjectESLint; 18 | loadESLint: (() => Promise) | undefined; 19 | }; 20 | notice(`ESLint version: ${ESLint.version}`); 21 | 22 | const configPath = getInput('config-path'); 23 | if (configPath) { 24 | const absoluteConfigPath = resolve(absoluteDirectory, configPath); 25 | notice(`Using ESLint config from: ${absoluteConfigPath}`); 26 | const eslint = new ESLint({ overrideConfigFile: absoluteConfigPath }); 27 | return eslint; 28 | } 29 | 30 | if (loadESLint) { 31 | // ESLint 8.57.0 and later 32 | notice('Using ESLint with default configuration'); 33 | const eslint = new (await loadESLint())(); 34 | return eslint; 35 | } 36 | 37 | const eslintConfig = (await new ESLint().calculateConfigForFile( 38 | 'package.json', 39 | )) as ProjectLinter.Config | undefined; 40 | if (!eslintConfig) { 41 | throw new Error( 42 | 'Failed to find ESLint configuration. Please set the config-path input.', 43 | ); 44 | } 45 | const eslint = new ESLint({ baseConfig: eslintConfig }); 46 | return eslint; 47 | } 48 | -------------------------------------------------------------------------------- /src/getESLintResults.ts: -------------------------------------------------------------------------------- 1 | import type { ESLint } from 'eslint'; 2 | import { getInput } from '@actions/core'; 3 | import { sync } from 'glob'; 4 | 5 | export async function getESLintResults(eslint: ESLint) { 6 | const targets = getInput('targets'); 7 | return eslint.lintFiles(targets ? sync(targets) : []); 8 | } 9 | -------------------------------------------------------------------------------- /src/getIndexedModifiedLines.ts: -------------------------------------------------------------------------------- 1 | import type { components } from '@octokit/openapi-types/types.js'; 2 | import { info } from '@actions/core'; 3 | 4 | const HUNK_HEADER_PATTERN = /^@@ -\d+(,\d+)? \+(\d+)(,(\d+))? @@/; 5 | 6 | export function getIndexedModifiedLines( 7 | file: components['schemas']['diff-entry'], 8 | ): { 9 | [line: string]: true; 10 | } { 11 | const modifiedLines = []; 12 | const indexedModifiedLines: { [line: string]: true } = {}; 13 | let currentLine = 0; 14 | let remainingLinesInHunk = 0; 15 | const lines = file.patch?.split('\n'); 16 | if (lines) { 17 | for (const line of lines) { 18 | if (remainingLinesInHunk === 0) { 19 | const matches = line.match(HUNK_HEADER_PATTERN); 20 | currentLine = parseInt(matches?.[2] || '1'); 21 | remainingLinesInHunk = parseInt(matches?.[4] || '1'); 22 | if (!currentLine || !remainingLinesInHunk) { 23 | throw new Error( 24 | `Expecting hunk header in ${file.filename} but seeing ${line}.`, 25 | ); 26 | } 27 | } else if (line[0] === '-') { 28 | continue; 29 | } else { 30 | if (line[0] === '+') { 31 | modifiedLines.push(currentLine); 32 | indexedModifiedLines[currentLine] = true; 33 | } 34 | currentLine++; 35 | remainingLinesInHunk--; 36 | } 37 | } 38 | } 39 | 40 | info(` File modified lines: ${modifiedLines.join()}`); 41 | if (file.patch !== undefined) { 42 | info( 43 | ` File patch: \n${file.patch 44 | .split('\n') 45 | .map((line) => ' ' + line) 46 | .join('\n')}\n`, 47 | ); 48 | } 49 | 50 | return indexedModifiedLines; 51 | } 52 | -------------------------------------------------------------------------------- /src/getOctokit.ts: -------------------------------------------------------------------------------- 1 | import { GitHub, getOctokitOptions } from '@actions/github/lib/utils.js'; 2 | import { type Octokit } from '@octokit/core/dist-types/index.js'; 3 | import { type PaginateInterface } from '@octokit/plugin-paginate-rest'; 4 | import { type Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 5 | import { retry } from '@octokit/plugin-retry'; 6 | import { throttling } from '@octokit/plugin-throttling'; 7 | 8 | export function getOctokit(githubToken: string): Octokit & 9 | Api & { 10 | paginate: PaginateInterface; 11 | } { 12 | const Octokit = GitHub.plugin(throttling, retry); 13 | const octokit = new Octokit( 14 | getOctokitOptions(githubToken, { 15 | throttle: { 16 | onRateLimit: (retryAfter, options, _, retryCount) => { 17 | if (retryCount === 0) { 18 | octokit.log.warn( 19 | `Request quota exhausted for request ${options.method} ${options.url}`, 20 | ); 21 | octokit.log.info(`Retrying after ${retryAfter} seconds!`); 22 | return true; 23 | } else { 24 | octokit.log.error( 25 | `Request quota exhausted for request ${options.method} ${options.url}`, 26 | ); 27 | } 28 | }, 29 | onSecondaryRateLimit: (retryAfter, options, _, retryCount) => { 30 | if (retryCount === 0) { 31 | octokit.log.warn( 32 | `Abuse detected for request ${options.method} ${options.url}`, 33 | ); 34 | octokit.log.info(`Retrying after ${retryAfter} seconds!`); 35 | return true; 36 | } else { 37 | octokit.log.warn( 38 | `Abuse detected for request ${options.method} ${options.url}`, 39 | ); 40 | } 41 | }, 42 | }, 43 | retry: { 44 | doNotRetry: ['429'], 45 | }, 46 | }), 47 | ); 48 | octokit.graphql = octokit.graphql.defaults({ 49 | headers: { 50 | 'X-GitHub-Next-Global-ID': 1, 51 | }, 52 | }); 53 | return octokit; 54 | } 55 | -------------------------------------------------------------------------------- /src/getPullRequestMetadata.ts: -------------------------------------------------------------------------------- 1 | import type { Octokit } from '@octokit/core'; 2 | import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; 3 | import type { PullRequestEvent } from '@octokit/webhooks-types/schema.d.ts'; 4 | import { info } from '@actions/core'; 5 | import { context } from '@actions/github'; 6 | 7 | export function getPullRequestMetadata() { 8 | const pullRequest = (context.payload as PullRequestEvent).pull_request; 9 | const owner = context.repo.owner; 10 | const repo = context.repo.repo; 11 | const pullRequestNumber = pullRequest.number; 12 | const baseSha = pullRequest.base.sha; 13 | const headSha = pullRequest.head.sha; 14 | 15 | info(`Owner: ${owner}`); 16 | info(`Repo: ${repo}`); 17 | info(`Pull Request number: ${pullRequestNumber}`); 18 | info(`Base SHA: ${baseSha}`); 19 | info(`Head SHA: ${headSha}`); 20 | 21 | return { 22 | owner, 23 | repo, 24 | pullRequestNumber, 25 | baseSha, 26 | headSha, 27 | }; 28 | } 29 | 30 | export async function getPullRequestMetadataByNumber( 31 | octokit: Octokit & Api, 32 | pullRequestNumber: number, 33 | ) { 34 | const owner = context.repo.owner; 35 | const repo = context.repo.repo; 36 | const response = await octokit.rest.pulls.get({ 37 | owner, 38 | repo, 39 | pull_number: pullRequestNumber, 40 | }); 41 | const pullRequest = response.data; 42 | const baseSha = pullRequest.base.sha; 43 | const headSha = pullRequest.head.sha; 44 | 45 | info(`Owner: ${owner}`); 46 | info(`Repo: ${repo}`); 47 | info(`Pull Request number: ${pullRequestNumber}`); 48 | info(`Base SHA: ${baseSha}`); 49 | info(`Head SHA: ${headSha}`); 50 | 51 | return { 52 | owner, 53 | repo, 54 | pullRequestNumber, 55 | baseSha, 56 | headSha, 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /src/getPushMetadata.ts: -------------------------------------------------------------------------------- 1 | import type { PushEvent } from '@octokit/webhooks-types/schema.d.ts'; 2 | import { info } from '@actions/core'; 3 | import { context } from '@actions/github'; 4 | 5 | export function getPushMetadata() { 6 | const push = context.payload as PushEvent; 7 | const owner = context.repo.owner; 8 | const repo = context.repo.repo; 9 | const beforeSha = push.before; 10 | const afterSha = push.after; 11 | 12 | info(`Owner: ${owner}`); 13 | info(`Repo: ${repo}`); 14 | info(`Before SHA: ${beforeSha}`); 15 | info(`After SHA: ${afterSha}`); 16 | 17 | return { 18 | owner, 19 | repo, 20 | beforeSha, 21 | afterSha, 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-always-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "always"]*/ 4 | let foo = () => { 5 | return 0; 6 | }; 7 | let foo = (retv, name) => { 8 | retv[name] = true; 9 | return retv; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-always-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "always"]*/ 4 | let foo = () => 0; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-asNeeded-requireReturnForObjectLiteralTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ 4 | let foo = () => {}; 5 | let foo = () => { return { bar: 0 }; }; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-asNeeded-requireReturnForObjectLiteralTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ 4 | let foo = () => ({}); 5 | let foo = () => ({ bar: 0 }); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "as-needed"]*/ 4 | let foo = () => 0; 5 | let foo = (retv, name) => { 6 | retv[name] = true; 7 | return retv; 8 | }; 9 | let foo = () => ({ 10 | bar: { 11 | foo: 1, 12 | bar: 2, 13 | } 14 | }); 15 | let foo = () => { bar(); }; 16 | let foo = () => {}; 17 | let foo = () => { /* do nothing */ }; 18 | let foo = () => { 19 | // do nothing. 20 | }; 21 | let foo = () => ({ bar: 0 }); 22 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "as-needed"]*/ 4 | let foo = () => { 5 | return 0; 6 | }; 7 | let foo = () => { 8 | return { 9 | bar: { 10 | foo: 1, 11 | bar: 2, 12 | } 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-never-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "never"]*/ 4 | let foo = () => 0; 5 | let foo = () => ({ foo: 0 }); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/arrow-body-style-never-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-body-style */ 3 | /*eslint arrow-body-style: ["error", "never"]*/ 4 | let foo = () => { 5 | return 0; 6 | }; 7 | let foo = (retv, name) => { 8 | retv[name] = true; 9 | return retv; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-always-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always"] */ 4 | // Capitalized comment 5 | 6 | // 1. Non-letter at beginning of comment 7 | 8 | // 丈 Non-Latin character at beginning of comment 9 | 10 | /* istanbul ignore next */ 11 | /* jscs:enable */ 12 | /* jshint asi:true */ 13 | /* global foo */ 14 | /* globals foo */ 15 | /* exported myVar */ 16 | /* eslint semi:off */ 17 | /* eslint-disable */ 18 | /* eslint-enable */ 19 | // eslint-disable-line 20 | // eslint-disable-next-line 21 | // https://github.com 22 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-always-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always"] */ 4 | // lowercase comment 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-blockIgnorePattern-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */ 4 | // Uppercase line comment, this is correct 5 | /* blockignore lowercase block comment, this is correct due to ignorePattern */ 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-blockIgnorePattern-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "block": { "ignorePattern": "blockignore" } }] */ 4 | // capitalized line comment, this is incorrect, blockignore does not help here 5 | /* lowercased block comment, this is incorrect too */ 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error"] */ 4 | // Capitalized comment 5 | 6 | // 1. Non-letter at beginning of comment 7 | 8 | // 丈 Non-Latin character at beginning of comment 9 | 10 | /* istanbul ignore next */ 11 | /* jscs:enable */ 12 | /* jshint asi:true */ 13 | /* global foo */ 14 | /* globals foo */ 15 | /* exported myVar */ 16 | /* eslint semi:off */ 17 | /* eslint-disable */ 18 | /* eslint-enable */ 19 | // eslint-disable-line 20 | // eslint-disable-next-line 21 | // https://github.com 22 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-ignoreConsecutiveCommentsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */ 4 | foo(); 5 | // This comment is valid since it has the correct capitalization. 6 | // this comment is ignored since it follows another comment, 7 | // and this one as well because it follows yet another comment. 8 | 9 | bar(); 10 | /* Here is a block comment which has the correct capitalization, */ 11 | /* but this one is ignored due to being consecutive; */ 12 | /* 13 | * in fact, even if any of these are multi-line, that is fine too. 14 | */ -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-ignoreConsecutiveCommentsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */ 4 | foo(); 5 | // this comment is invalid, but only on this line. 6 | // this comment does NOT get reported, since it is a consecutive comment. -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-ignoreInlineCommentsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "ignoreInlineComments": true }] */ 4 | function foo(/* ignored */ a) { 5 | } -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-ignorePatternPragma-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "always", { "ignorePattern": "pragma" }] */ 4 | function foo() { 5 | /* pragma wrap(true) */ 6 | } -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error"] */ 4 | // lowercase comment 5 | 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-never-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "never"] */ 4 | // lowercase comment 5 | 6 | // 1. Non-letter at beginning of comment 7 | 8 | // 丈 Non-Latin character at beginning of comment 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/capitalized-comments-never-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable capitalized-comments */ 3 | /* eslint capitalized-comments: ["error", "never"] */ 4 | // Capitalized comment 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: "error"*/ 4 | if (foo) { 5 | foo++; 6 | } 7 | 8 | while (bar) { 9 | baz(); 10 | } 11 | 12 | if (foo) { 13 | baz(); 14 | } else { 15 | qux(); 16 | } 17 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: "error"*/ 4 | if (foo) foo++; 5 | 6 | while (bar) 7 | baz(); 8 | 9 | if (foo) { 10 | baz(); 11 | } else qux(); 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multi-consistent-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi", "consistent"]*/ 4 | if (foo) { 5 | bar(); 6 | baz(); 7 | } else { 8 | buz(); 9 | } 10 | 11 | if (foo) { 12 | bar(); 13 | } else if (faa) { 14 | bor(); 15 | } else { 16 | other(); 17 | things(); 18 | } 19 | 20 | if (true) 21 | foo(); 22 | else 23 | baz(); 24 | 25 | if (foo) 26 | foo++; 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multi-consistent-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi", "consistent"]*/ 4 | if (foo) { 5 | bar(); 6 | baz(); 7 | } else 8 | buz(); 9 | 10 | if (foo) 11 | bar(); 12 | else if (faa) 13 | bor(); 14 | else { 15 | other(); 16 | things(); 17 | } 18 | 19 | if (true) 20 | foo(); 21 | else { 22 | baz(); 23 | } 24 | 25 | if (foo) { 26 | foo++; 27 | } 28 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multi-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi"]*/ 4 | if (foo) foo++; 5 | 6 | else foo(); 7 | 8 | while (true) { 9 | doSomething(); 10 | doSomethingElse(); 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multi-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi"]*/ 4 | if (foo) { 5 | foo++; 6 | } 7 | 8 | if (foo) bar(); 9 | else { 10 | foo++; 11 | } 12 | 13 | while (true) { 14 | doSomething(); 15 | } 16 | 17 | for (var i=0; i < items.length; i++) { 18 | doSomething(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multiLine-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi-line"]*/ 4 | if (foo) foo++; else doSomething(); 5 | 6 | if (foo) foo++; 7 | else if (bar) baz() 8 | else doSomething(); 9 | 10 | do something(); 11 | while (foo); 12 | 13 | while (foo 14 | && bar) baz(); 15 | 16 | if (foo) { 17 | foo++; 18 | } 19 | 20 | if (foo) { foo++; } 21 | 22 | while (true) { 23 | doSomething(); 24 | doSomethingElse(); 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multiLine-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi-line"]*/ 4 | if (foo) 5 | doSomething(); 6 | else 7 | doSomethingElse(); 8 | 9 | if (foo) foo( 10 | bar, 11 | baz); 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multiOrNest-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi-or-nest"]*/ 4 | if (!foo) { 5 | foo = { 6 | bar: baz, 7 | qux: foo 8 | }; 9 | } 10 | 11 | while (true) { 12 | if(foo) 13 | doSomething(); 14 | else 15 | doSomethingElse(); 16 | } 17 | 18 | if (foo) 19 | foo++; 20 | 21 | while (true) 22 | doSomething(); 23 | 24 | for (var i = 0; foo; i++) 25 | doSomething(); 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/curly-multiOrNest-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable curly */ 3 | /*eslint curly: ["error", "multi-or-nest"]*/ 4 | if (!foo) 5 | foo = { 6 | bar: baz, 7 | qux: foo 8 | }; 9 | 10 | while (true) 11 | if(foo) 12 | doSomething(); 13 | else 14 | doSomethingElse(); 15 | 16 | if (foo) { 17 | foo++; 18 | } 19 | 20 | while (true) { 21 | doSomething(); 22 | } 23 | 24 | for (var i = 0; foo; i++) { 25 | doSomething(); 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline-consistent.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-newline */ 3 | function incorrect() { 4 | /*eslint array-bracket-newline: ["error", "consistent"]*/ 5 | 6 | var a = [1 7 | ]; 8 | var b = [ 9 | 1]; 10 | var c = [function foo() { 11 | dosomething(); 12 | } 13 | ] 14 | var d = [ 15 | function foo() { 16 | dosomething(); 17 | }] 18 | } 19 | 20 | function correct() { 21 | /*eslint array-bracket-newline: ["error", "consistent"]*/ 22 | 23 | var a = []; 24 | var b = [ 25 | ]; 26 | var c = [1]; 27 | var d = [ 28 | 1 29 | ]; 30 | var e = [function foo() { 31 | dosomething(); 32 | }]; 33 | var f = [ 34 | function foo() { 35 | dosomething(); 36 | } 37 | ]; 38 | } 39 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline-minItems.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-newline */ 3 | function incorrect() { 4 | /*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ 5 | 6 | var a = [ 7 | ]; 8 | var b = [ 9 | 1 10 | ]; 11 | var c = [1, 2]; 12 | var d = [1, 13 | 2]; 14 | var e = [ 15 | function foo() { 16 | dosomething(); 17 | } 18 | ]; 19 | } 20 | 21 | function correct() { 22 | /*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ 23 | 24 | var a = []; 25 | var b = [1]; 26 | var c = [ 27 | 1, 2 28 | ]; 29 | var d = [ 30 | 1, 31 | 2 32 | ]; 33 | var e = [function foo() { 34 | dosomething(); 35 | }]; 36 | } 37 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline-multilineTrue-minItems.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-newline */ 3 | /*eslint array-bracket-newline: ["error", { "multiline": true, "minItems": 2 }]*/ 4 | function incorrect() { 5 | var a = [ 6 | ]; 7 | var b = [ 8 | 1 9 | ]; 10 | var c = [1, 2]; 11 | var d = [1, 12 | 2]; 13 | var e = [function foo() { 14 | dosomething(); 15 | }]; 16 | } 17 | 18 | function correct() { 19 | var a = []; 20 | var b = [1]; 21 | var c = [ 22 | 1, 2 23 | ]; 24 | var d = [ 25 | 1, 26 | 2 27 | ]; 28 | var e = [ 29 | function foo() { 30 | dosomething(); 31 | } 32 | ]; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline-multilineTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-newline */ 3 | /*eslint array-bracket-newline: ["error", { "multiline": true }]*/ 4 | function incorrect() { 5 | var a = [ 6 | ]; 7 | var b = [ 8 | 1 9 | ]; 10 | var c = [ 11 | 1, 2 12 | ]; 13 | var d = [1, 14 | 2]; 15 | var e = [function foo() { 16 | dosomething(); 17 | }]; 18 | } 19 | 20 | function correct() { 21 | var a = []; 22 | var b = [1]; 23 | var c = [1, 2]; 24 | var d = [ 25 | 1, 26 | 2 27 | ]; 28 | var e = [ 29 | function foo() { 30 | dosomething(); 31 | } 32 | ]; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline-never.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-newline */ 3 | /*eslint array-bracket-newline: ["error", "never"]*/ 4 | function incorrect() { 5 | var a = [ 6 | ]; 7 | var b = [ 8 | 1 9 | ]; 10 | var c = [ 11 | 1, 2 12 | ]; 13 | var d = [ 14 | 1, 15 | 2 16 | ]; 17 | var e = [ 18 | function foo() { 19 | dosomething(); 20 | } 21 | ]; 22 | } 23 | 24 | function correct() { 25 | var a = []; 26 | var b = [1]; 27 | var c = [1, 2]; 28 | var d = [1, 29 | 2]; 30 | var e = [function foo() { 31 | dosomething(); 32 | }]; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-newline.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable eslint array-bracket-newline */ 3 | /*eslint array-bracket-newline: ["error", "always"]*/ 4 | function incorrect() { 5 | var a = []; 6 | var b = [1]; 7 | var c = [1, 2]; 8 | var d = [1, 9 | 2]; 10 | var e = [function foo() { 11 | dosomething(); 12 | }]; 13 | } 14 | 15 | function correct() { 16 | var a = [ 17 | ]; 18 | var b = [ 19 | 1 20 | ]; 21 | var c = [ 22 | 1, 2 23 | ]; 24 | var d = [ 25 | 1, 26 | 2 27 | ]; 28 | var e = [ 29 | function foo() { 30 | dosomething(); 31 | } 32 | ]; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-spacing-always.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-spacing */ 3 | function incorrect() { 4 | /*eslint array-bracket-spacing: ["error", "always"]*/ 5 | /*eslint-env es6*/ 6 | 7 | var arr = ['foo', 'bar']; 8 | var arr = ['foo', 'bar' ]; 9 | var arr = [ ['foo'], 'bar' ]; 10 | var arr = ['foo', 11 | 'bar' 12 | ]; 13 | var arr = [ 14 | 'foo', 15 | 'bar']; 16 | 17 | var [x, y] = z; 18 | var [x,y] = z; 19 | var [x, ...y] = z; 20 | var [,,x,] = z; 21 | } 22 | 23 | function correct() { 24 | /*eslint array-bracket-spacing: ["error", "always"]*/ 25 | /*eslint-env es6*/ 26 | 27 | var arr = []; 28 | var arr = [ 'foo', 'bar', 'baz' ]; 29 | var arr = [ [ 'foo' ], 'bar', 'baz' ]; 30 | var arr = [ 'foo', 31 | 'bar' 32 | ]; 33 | var arr = [ 34 | 'foo', 35 | 'bar' ]; 36 | var arr = [ 37 | 'foo', 38 | 'bar', 39 | 'baz' 40 | ]; 41 | 42 | var [ x, y ] = z; 43 | var [ x,y ] = z; 44 | var [ x, ...y ] = z; 45 | var [ ,,x, ] = z; 46 | } 47 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-spacing-arraysInArraysFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-spacing */ 3 | function incorrect() { 4 | /*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/ 5 | 6 | var arr = [ [ 1, 2 ], 2, 3, 4 ]; 7 | var arr = [ [ 1, 2 ], 2, [ 3, 4 ] ]; 8 | } 9 | 10 | function correct() { 11 | /*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/ 12 | 13 | var arr = [[ 1, 2 ], 2, 3, 4 ]; 14 | var arr = [[ 1, 2 ], 2, [ 3, 4 ]]; 15 | } 16 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-spacing-objectsInArraysFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-spacing */ 3 | function incorrect() { 4 | /*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/ 5 | 6 | var arr = [ { 'foo': 'bar' } ]; 7 | var arr = [ { 8 | 'foo': 'bar' 9 | } ] 10 | } 11 | 12 | function correct() { 13 | /*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/ 14 | 15 | var arr = [{ 'foo': 'bar' }]; 16 | var arr = [{ 17 | 'foo': 'bar' 18 | }]; 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-spacing-singleValueFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-spacing */ 3 | function incorrect() { 4 | /*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/ 5 | 6 | var foo = [ 'foo' ]; 7 | var foo = [ 'foo']; 8 | var foo = ['foo' ]; 9 | var foo = [ 1 ]; 10 | var foo = [ 1]; 11 | var foo = [1 ]; 12 | var foo = [ [ 1, 2 ] ]; 13 | var foo = [ { 'foo': 'bar' } ]; 14 | } 15 | 16 | function correct() { 17 | /*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/ 18 | 19 | var foo = ['foo']; 20 | var foo = [1]; 21 | var foo = [[ 1, 1 ]]; 22 | var foo = [{ 'foo': 'bar' }]; 23 | } 24 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-bracket-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-bracket-spacing */ 3 | /*eslint array-bracket-spacing: ["error", "never"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | var arr = [ 'foo', 'bar' ]; 8 | var arr = ['foo', 'bar' ]; 9 | var arr = [ ['foo'], 'bar']; 10 | var arr = [[ 'foo' ], 'bar']; 11 | var arr = [ 'foo', 12 | 'bar' 13 | ]; 14 | var [ x, y ] = z; 15 | var [ x,y ] = z; 16 | var [ x, ...y ] = z; 17 | var [ ,,x, ] = z; 18 | } 19 | 20 | function correct() { 21 | /*eslint-env es6*/ 22 | 23 | var arr = []; 24 | var arr = ['foo', 'bar', 'baz']; 25 | var arr = [['foo'], 'bar', 'baz']; 26 | var arr = [ 27 | 'foo', 28 | 'bar', 29 | 'baz' 30 | ]; 31 | var arr = ['foo', 32 | 'bar' 33 | ]; 34 | var arr = [ 35 | 'foo', 36 | 'bar']; 37 | 38 | var [x, y] = z; 39 | var [x,y] = z; 40 | var [x, ...y] = z; 41 | var [,,x,] = z; 42 | } 43 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-ArrayExpressionAlways-ArrayPatternNever.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | function incorrect() { 4 | /*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/ 5 | 6 | var a = [1, 2]; 7 | var b = [1, 2, 3]; 8 | var c = [ 9 | function foo() { 10 | dosomething(); 11 | }, function bar() { 12 | dosomething(); 13 | } 14 | ]; 15 | 16 | var [d, 17 | e] = arr; 18 | var [f, 19 | g, 20 | h] = arr; 21 | var [i = function foo() { 22 | dosomething() 23 | }, 24 | j = function bar() { 25 | dosomething() 26 | }] = arr 27 | } 28 | 29 | function correct() { 30 | /*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/ 31 | 32 | var a = [1, 33 | 2]; 34 | var b = [1, 35 | 2, 36 | 3]; 37 | var c = [ 38 | function foo() { 39 | dosomething(); 40 | }, 41 | function bar() { 42 | dosomething(); 43 | } 44 | ]; 45 | 46 | var [d, e] = arr 47 | var [f, g, h] = arr 48 | var [i = function foo() { 49 | dosomething() 50 | }, j = function bar() { 51 | dosomething() 52 | }] = arr 53 | } 54 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-consistent.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", "consistent"]*/ 4 | function incorrect() { 5 | var a = [ 6 | 1, 2, 7 | 3 8 | ]; 9 | var b = [ 10 | function foo() { 11 | dosomething(); 12 | }, function bar() { 13 | dosomething(); 14 | }, 15 | function baz() { 16 | dosomething(); 17 | } 18 | ]; 19 | } 20 | 21 | function correct() { 22 | var a = []; 23 | var b = [1]; 24 | var c = [1, 2]; 25 | var d = [1, 2, 3]; 26 | var e = [ 27 | 1, 28 | 2 29 | ]; 30 | var f = [ 31 | 1, 32 | 2, 33 | 3 34 | ]; 35 | var g = [ 36 | function foo() { 37 | dosomething(); 38 | }, function bar() { 39 | dosomething(); 40 | }, function baz() { 41 | dosomething(); 42 | } 43 | ]; 44 | var h = [ 45 | function foo() { 46 | dosomething(); 47 | }, 48 | function bar() { 49 | dosomething(); 50 | }, 51 | function baz() { 52 | dosomething(); 53 | } 54 | ]; 55 | } 56 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-minItems.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", { "minItems": 3 }]*/ 4 | function incorrect() { 5 | var c = [1, 6 | 2]; 7 | var d = [1, 2, 3]; 8 | var e = [ 9 | function foo() { 10 | dosomething(); 11 | }, 12 | function bar() { 13 | dosomething(); 14 | } 15 | ]; 16 | } 17 | 18 | function correct() { 19 | var a = []; 20 | var b = [1]; 21 | var c = [1, 2]; 22 | var d = [1, 23 | 2, 24 | 3]; 25 | var e = [ 26 | function foo() { 27 | dosomething(); 28 | }, function bar() { 29 | dosomething(); 30 | } 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-multilineTrue-minItems.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/ 4 | function incorrect() { 5 | var c = [1, 6 | 2]; 7 | var d = [1, 2, 3]; 8 | var e = [ 9 | function foo() { 10 | dosomething(); 11 | }, function bar() { 12 | dosomething(); 13 | } 14 | ]; 15 | } 16 | 17 | function correct() { 18 | var a = []; 19 | var b = [1]; 20 | var c = [1, 2]; 21 | var d = [1, 22 | 2, 23 | 3]; 24 | var e = [ 25 | function foo() { 26 | dosomething(); 27 | }, 28 | function bar() { 29 | dosomething(); 30 | } 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-multilineTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", { "multiline": true }]*/ 4 | function incorrect() { 5 | var d = [1, 6 | 2, 3]; 7 | var e = [ 8 | function foo() { 9 | dosomething(); 10 | }, function bar() { 11 | dosomething(); 12 | } 13 | ]; 14 | } 15 | 16 | function correct() { 17 | var a = []; 18 | var b = [1]; 19 | var c = [1, 2]; 20 | var d = [1, 2, 3]; 21 | var e = [ 22 | function foo() { 23 | dosomething(); 24 | }, 25 | function bar() { 26 | dosomething(); 27 | } 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline-never.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", "never"]*/ 4 | function incorrect() { 5 | var c = [ 6 | 1, 7 | 2 8 | ]; 9 | var d = [ 10 | 1, 11 | 2, 12 | 3 13 | ]; 14 | var e = [ 15 | function foo() { 16 | dosomething(); 17 | }, 18 | function bar() { 19 | dosomething(); 20 | } 21 | ]; 22 | } 23 | 24 | function correct() { 25 | var a = []; 26 | var b = [1]; 27 | var c = [1, 2]; 28 | var d = [1, 2, 3]; 29 | var e = [ 30 | 1, 2, 3]; 31 | var f = [ 32 | 1, 2, 3 33 | ]; 34 | var g = [ 35 | function foo() { 36 | dosomething(); 37 | }, function bar() { 38 | dosomething(); 39 | } 40 | ]; 41 | } 42 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/array-element-newline.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-element-newline */ 3 | /*eslint array-element-newline: ["error", "always"]*/ 4 | function incorrect() { 5 | var c = [1, 2]; 6 | var d = [1, 2, 3]; 7 | var e = [1, 2, 3 8 | ]; 9 | var f = [ 10 | 1, 2, 3 11 | ]; 12 | var g = [ 13 | function foo() { 14 | dosomething(); 15 | }, function bar() { 16 | dosomething(); 17 | } 18 | ]; 19 | } 20 | 21 | function correct() { 22 | var a = []; 23 | var b = [1]; 24 | var c = [1, 25 | 2]; 26 | var d = [1, 27 | 2, 28 | 3]; 29 | var d = [ 30 | 1, 31 | 2, 32 | 3 33 | ]; 34 | var e = [ 35 | function foo() { 36 | dosomething(); 37 | }, 38 | function bar() { 39 | dosomething(); 40 | } 41 | ]; 42 | } 43 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-parens-asNeeded.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-parens */ 3 | /*eslint arrow-parens: ["error", "as-needed"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | (a) => {}; 8 | (a) => a; 9 | (a) => {'\n'}; 10 | a.then((foo) => {}); 11 | a.then((foo) => a); 12 | a((foo) => { if (true) {} }); 13 | const f = /** @type {number} */(a) => a + a; 14 | const g = /* comment */ (a) => a + a; 15 | const h = (a) /* comment */ => a + a; 16 | } 17 | 18 | function correct() { 19 | /*eslint-env es6*/ 20 | 21 | () => {}; 22 | a => {}; 23 | a => a; 24 | a => {'\n'}; 25 | a.then(foo => {}); 26 | a.then(foo => { if (true) {} }); 27 | (a, b, c) => a; 28 | (a = 10) => a; 29 | ([a, b]) => a; 30 | ({a, b}) => a; 31 | const f = (/** @type {number} */a) => a + a; 32 | const g = (/* comment */ a) => a + a; 33 | const h = (a /* comment */) => a + a; 34 | } 35 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-parens-requireForBlockBodyTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-parens */ 3 | /*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | (a) => a; 8 | a => {}; 9 | a => {'\n'}; 10 | a.map((x) => x * x); 11 | a.map(x => { 12 | return x * x; 13 | }); 14 | a.then(foo => {}); 15 | } 16 | 17 | function correct() { 18 | /*eslint-env es6*/ 19 | 20 | (a) => {}; 21 | (a) => {'\n'}; 22 | a => ({}); 23 | () => {}; 24 | a => a; 25 | a.then((foo) => {}); 26 | a.then((foo) => { if (true) {} }); 27 | a((foo) => { if (true) {} }); 28 | (a, b, c) => a; 29 | (a = 10) => a; 30 | ([a, b]) => a; 31 | ({a, b}) => a; 32 | } 33 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-parens.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable eslint arrow-parens */ 3 | function incorrect() { 4 | /*eslint arrow-parens: ["error", "always"]*/ 5 | /*eslint-env es6*/ 6 | 7 | a => {}; 8 | a => a; 9 | a => {'\n'}; 10 | a.then(foo => {}); 11 | a.then(foo => a); 12 | a(foo => { if (true) {} }); 13 | } 14 | 15 | function correct() { 16 | /*eslint arrow-parens: ["error", "always"]*/ 17 | /*eslint-env es6*/ 18 | 19 | () => {}; 20 | (a) => {}; 21 | (a) => a; 22 | (a) => {'\n'} 23 | a.then((foo) => {}); 24 | a.then((foo) => { if (true) {} }); 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-spacing-beforeFalse-afterFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable eslint arrow-parens */ 3 | function incorrect() { 4 | /*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ 5 | /*eslint-env es6*/ 6 | 7 | () =>{}; 8 | (a) => {}; 9 | ()=> {'\n'}; 10 | } 11 | 12 | function correct() { 13 | /*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ 14 | /*eslint-env es6*/ 15 | 16 | ()=>{}; 17 | (a)=>{}; 18 | ()=>{'\n'}; 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-spacing-beforeFalse-afterTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable eslint arrow-parens */ 3 | function incorrect() { 4 | /*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ 5 | /*eslint-env es6*/ 6 | 7 | () =>{}; 8 | (a) => {}; 9 | ()=>{'\n'}; 10 | } 11 | 12 | function correct() { 13 | /*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ 14 | /*eslint-env es6*/ 15 | 16 | ()=> {}; 17 | (a)=> {}; 18 | ()=> {'\n'}; 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/arrow-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-spacing */ 3 | function incorrect() { 4 | /*eslint arrow-spacing: "error"*/ 5 | /*eslint-env es6*/ 6 | 7 | ()=> {}; 8 | () =>{}; 9 | (a)=> {}; 10 | (a) =>{}; 11 | a =>a; 12 | a=> a; 13 | ()=> {'\n'}; 14 | () =>{'\n'}; 15 | } 16 | 17 | function correct() { 18 | /*eslint arrow-spacing: "error"*/ 19 | /*eslint-env es6*/ 20 | 21 | () => {}; 22 | (a) => {}; 23 | a => a; 24 | () => {'\n'}; 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/block-spacing-never.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable arrow-spacing */ 3 | function incorrect() { 4 | /*eslint block-spacing: ["error", "never"]*/ 5 | 6 | function foo() { return true; } 7 | if (foo) { bar = 0;} 8 | 9 | class C { 10 | static { this.bar = 0; } 11 | } 12 | } 13 | 14 | function correct() { 15 | /*eslint block-spacing: ["error", "never"]*/ 16 | 17 | function foo() {return true;} 18 | if (foo) {bar = 0;} 19 | 20 | class C { 21 | static {this.bar = 0;} 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/block-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-spacing */ 3 | function incorrect() { 4 | /*eslint block-spacing: "error"*/ 5 | 6 | function foo() {return true;} 7 | if (foo) { bar = 0;} 8 | function baz() {let i = 0; 9 | return i; 10 | } 11 | 12 | class C { 13 | static {this.bar = 0;} 14 | } 15 | } 16 | 17 | function correct() { 18 | /*eslint block-spacing: "error"*/ 19 | 20 | function foo() { return true; } 21 | if (foo) { bar = 0; } 22 | 23 | class C { 24 | static { this.bar = 0; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style-allman-allowSingleLineTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function correct() { 4 | /*eslint brace-style: ["error", "allman", { "allowSingleLine": true }]*/ 5 | 6 | function nop() { return; } 7 | 8 | if (foo) { bar(); } 9 | 10 | if (foo) { bar(); } 11 | else { baz(); } 12 | 13 | try { somethingRisky(); } 14 | catch(e) { handleError(); } 15 | 16 | class C 17 | { 18 | static { foo(); } 19 | 20 | static 21 | { foo(); } 22 | } 23 | 24 | class D { static { foo(); } } 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style-allman.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function incorrect() { 4 | /*eslint brace-style: ["error", "allman"]*/ 5 | 6 | function foo() { 7 | return true; 8 | } 9 | 10 | if (foo) 11 | { 12 | bar(); } 13 | 14 | try 15 | { 16 | somethingRisky(); 17 | } catch(e) 18 | { 19 | handleError(); 20 | } 21 | 22 | class C { 23 | static { 24 | foo(); 25 | } 26 | } 27 | 28 | if (foo) { 29 | bar(); 30 | } else { 31 | baz(); 32 | } 33 | } 34 | 35 | function correct() { 36 | /*eslint brace-style: ["error", "allman"]*/ 37 | 38 | function foo() 39 | { 40 | return true; 41 | } 42 | 43 | if (foo) 44 | { 45 | bar(); 46 | } 47 | 48 | if (foo) 49 | { 50 | bar(); 51 | } 52 | else 53 | { 54 | baz(); 55 | } 56 | 57 | try 58 | { 59 | somethingRisky(); 60 | } 61 | catch(e) 62 | { 63 | handleError(); 64 | } 65 | 66 | class C 67 | { 68 | static 69 | { 70 | foo(); 71 | } 72 | } 73 | 74 | // when there are no braces, there are no problems 75 | if (foo) bar(); 76 | else if (baz) boom(); 77 | } 78 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style-allowSingleLineTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function correct() { 4 | /*eslint brace-style: ["error", "1tbs", { "allowSingleLine": true }]*/ 5 | 6 | function nop() { return; } 7 | 8 | if (foo) { bar(); } 9 | 10 | if (foo) { bar(); } else { baz(); } 11 | 12 | try { somethingRisky(); } catch(e) { handleError(); } 13 | 14 | if (foo) { baz(); } else { 15 | boom(); 16 | } 17 | 18 | if (foo) { baz(); } else if (bar) { 19 | boom(); 20 | } 21 | 22 | if (foo) { baz(); } else 23 | if (bar) { 24 | boom(); 25 | } 26 | 27 | if (foo) { baz(); } else if (bar) { 28 | boom(); 29 | } 30 | 31 | try { somethingRisky(); } catch(e) { 32 | handleError(); 33 | } 34 | 35 | class C { 36 | static { foo(); } 37 | } 38 | 39 | class D { static { foo(); } } 40 | } 41 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style-stroustrup-allowSingleLineTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function correct() { 4 | /*eslint brace-style: ["error", "stroustrup", { "allowSingleLine": true }]*/ 5 | 6 | function nop() { return; } 7 | 8 | if (foo) { bar(); } 9 | 10 | if (foo) { bar(); } 11 | else { baz(); } 12 | 13 | try { somethingRisky(); } 14 | catch(e) { handleError(); } 15 | 16 | class C { 17 | static { foo(); } 18 | } 19 | 20 | class D { static { foo(); } } 21 | } 22 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style-stroustrup.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function incorrect() { 4 | /*eslint brace-style: ["error", "stroustrup"]*/ 5 | 6 | function foo() 7 | { 8 | return true; 9 | } 10 | 11 | if (foo) 12 | { 13 | bar(); 14 | } 15 | 16 | try 17 | { 18 | somethingRisky(); 19 | } catch(e) 20 | { 21 | handleError(); 22 | } 23 | 24 | class C 25 | { 26 | static 27 | { 28 | foo(); 29 | } 30 | } 31 | 32 | if (foo) { 33 | bar(); 34 | } else { 35 | baz(); 36 | } 37 | } 38 | 39 | function correct() { 40 | /*eslint brace-style: ["error", "stroustrup"]*/ 41 | 42 | function foo() { 43 | return true; 44 | } 45 | 46 | if (foo) { 47 | bar(); 48 | } 49 | 50 | if (foo) { 51 | bar(); 52 | } 53 | else { 54 | baz(); 55 | } 56 | 57 | try { 58 | somethingRisky(); 59 | } 60 | catch(e) { 61 | handleError(); 62 | } 63 | 64 | class C { 65 | static { 66 | foo(); 67 | } 68 | } 69 | 70 | // when there are no braces, there are no problems 71 | if (foo) bar(); 72 | else if (baz) boom(); 73 | } 74 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/brace-style.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable block-style */ 3 | function incorrect() { 4 | /*eslint brace-style: "error"*/ 5 | 6 | function foo() 7 | { 8 | return true; 9 | } 10 | 11 | if (foo) 12 | { 13 | bar(); 14 | } 15 | 16 | try 17 | { 18 | somethingRisky(); 19 | } catch(e) 20 | { 21 | handleError(); 22 | } 23 | 24 | if (foo) { 25 | bar(); 26 | } 27 | else { 28 | baz(); 29 | } 30 | 31 | class C 32 | { 33 | static 34 | { 35 | foo(); 36 | } 37 | } 38 | } 39 | 40 | function correct() { 41 | /*eslint brace-style: "error"*/ 42 | 43 | function foo() { 44 | return true; 45 | } 46 | 47 | if (foo) { 48 | bar(); 49 | } 50 | 51 | if (foo) { 52 | bar(); 53 | } else { 54 | baz(); 55 | } 56 | 57 | try { 58 | somethingRisky(); 59 | } catch(e) { 60 | handleError(); 61 | } 62 | 63 | class C { 64 | static { 65 | foo(); 66 | } 67 | } 68 | 69 | // when there are no braces, there are no problems 70 | if (foo) bar(); 71 | else if (baz) boom(); 72 | } 73 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle-always.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", "always"]*/ 4 | function incorrect() { 5 | var foo = { 6 | bar: "baz", 7 | qux: "quux" 8 | }; 9 | 10 | var arr = [1,2]; 11 | 12 | foo({ 13 | bar: "baz", 14 | qux: "quux" 15 | }); 16 | } 17 | 18 | function correct() { 19 | var foo = { 20 | bar: "baz", 21 | qux: "quux", 22 | }; 23 | 24 | var arr = [1,2,]; 25 | 26 | foo({ 27 | bar: "baz", 28 | qux: "quux", 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle-alwaysMultiline.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", "always-multiline"]*/ 4 | function incorrect() { 5 | var foo = { 6 | bar: "baz", 7 | qux: "quux" 8 | }; 9 | 10 | var foo = { bar: "baz", qux: "quux", }; 11 | 12 | var arr = [1,2,]; 13 | 14 | var arr = [1, 15 | 2,]; 16 | 17 | var arr = [ 18 | 1, 19 | 2 20 | ]; 21 | 22 | foo({ 23 | bar: "baz", 24 | qux: "quux" 25 | }); 26 | } 27 | 28 | function correct() { 29 | 30 | var foo = { 31 | bar: "baz", 32 | qux: "quux", 33 | }; 34 | 35 | var foo = {bar: "baz", qux: "quux"}; 36 | var arr = [1,2]; 37 | 38 | var arr = [1, 39 | 2]; 40 | 41 | var arr = [ 42 | 1, 43 | 2, 44 | ]; 45 | 46 | foo({ 47 | bar: "baz", 48 | qux: "quux", 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle-functionsAlways.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", {"functions": "always"}]*/ 4 | function incorrect() { 5 | function foo(a, b) { 6 | } 7 | 8 | foo(a, b); 9 | new foo(a, b); 10 | } 11 | 12 | function correct() { 13 | 14 | function foo(a, b,) { 15 | } 16 | 17 | foo(a, b,); 18 | new foo(a, b,); 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle-functionsNever.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", {"functions": "never"}]*/ 4 | function incorrect() { 5 | function foo(a, b,) { 6 | } 7 | 8 | foo(a, b,); 9 | new foo(a, b,); 10 | } 11 | 12 | function correct() { 13 | function foo(a, b) { 14 | } 15 | 16 | foo(a, b); 17 | new foo(a, b); 18 | } 19 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle-onlyMultiline.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", "only-multiline"]*/ 4 | function incorrect() { 5 | var foo = { bar: "baz", qux: "quux", }; 6 | 7 | var arr = [1,2,]; 8 | 9 | var arr = [1, 10 | 2,]; 11 | } 12 | 13 | function correct() { 14 | 15 | var foo = { 16 | bar: "baz", 17 | qux: "quux", 18 | }; 19 | 20 | var foo = { 21 | bar: "baz", 22 | qux: "quux" 23 | }; 24 | 25 | var foo = {bar: "baz", qux: "quux"}; 26 | var arr = [1,2]; 27 | 28 | var arr = [1, 29 | 2]; 30 | 31 | var arr = [ 32 | 1, 33 | 2, 34 | ]; 35 | 36 | var arr = [ 37 | 1, 38 | 2 39 | ]; 40 | 41 | foo({ 42 | bar: "baz", 43 | qux: "quux", 44 | }); 45 | 46 | foo({ 47 | bar: "baz", 48 | qux: "quux" 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-dangle.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-dangle */ 3 | /*eslint comma-dangle: ["error", "never"]*/ 4 | function incorrect() { 5 | var foo = { 6 | bar: "baz", 7 | qux: "quux", 8 | }; 9 | 10 | var arr = [1,2,]; 11 | 12 | foo({ 13 | bar: "baz", 14 | qux: "quux", 15 | }); 16 | } 17 | 18 | function correct() { 19 | 20 | var foo = { 21 | bar: "baz", 22 | qux: "quux" 23 | }; 24 | 25 | var arr = [1,2]; 26 | 27 | foo({ 28 | bar: "baz", 29 | qux: "quux" 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-spacing-beforeTrue-afterFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-spacing */ 3 | /*eslint comma-spacing: ["error", { "before": true, "after": false }]*/ 4 | function incorrect() { 5 | var foo = 1, bar = 2; 6 | var arr = [1 , 2]; 7 | var obj = {"foo": "bar", "baz": "qur"}; 8 | new Foo(a,b); 9 | function foo(a,b){} 10 | a, b 11 | } 12 | 13 | function correct() { 14 | var foo = 1 ,bar = 2 , 15 | baz = true; 16 | var arr = [1 ,2]; 17 | var arr = [1 ,,3] 18 | var obj = {"foo": "bar" ,"baz": "qur"}; 19 | foo(a ,b); 20 | new Foo(a ,b); 21 | function foo(a ,b){} 22 | a ,b 23 | 24 | var arr = [,2 ,3] 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-spacing */ 3 | /*eslint comma-spacing: ["error", { "before": false, "after": true }]*/ 4 | function incorrect() { 5 | var foo = 1 ,bar = 2; 6 | var arr = [1 , 2]; 7 | var obj = {"foo": "bar" ,"baz": "qur"}; 8 | foo(a ,b); 9 | new Foo(a ,b); 10 | function foo(a ,b){} 11 | a ,b 12 | } 13 | 14 | function correct() { 15 | var foo = 1, bar = 2 16 | , baz = 3; 17 | var arr = [1, 2]; 18 | var arr = [1,, 3] 19 | var obj = {"foo": "bar", "baz": "qur"}; 20 | foo(a, b); 21 | new Foo(a, b); 22 | function foo(a, b){} 23 | a, b 24 | 25 | var arr = [ , 2, 3 ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-style-exceptions.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-style */ 3 | /*eslint comma-style: ["error", "first", { "exceptions": { "ArrayExpression": true, "ObjectExpression": true } }]*/ 4 | function incorrect() { 5 | var o = {}, 6 | a = []; 7 | } 8 | 9 | function correct() { 10 | var o = {fst:1, 11 | snd: [1, 12 | 2]} 13 | , a = []; 14 | } 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-style-first.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-style */ 3 | /*eslint comma-style: ["error", "first"]*/ 4 | function incorrect() { 5 | var foo = 1, 6 | bar = 2; 7 | 8 | var foo = ["apples", 9 | "oranges"]; 10 | 11 | function bar() { 12 | return { 13 | "a": 1, 14 | "b:": 2 15 | }; 16 | } 17 | } 18 | 19 | function correct() { 20 | var foo = 1, bar = 2; 21 | 22 | var foo = 1 23 | ,bar = 2; 24 | 25 | var foo = ["apples" 26 | ,"oranges"]; 27 | 28 | function bar() { 29 | return { 30 | "a": 1 31 | ,"b:": 2 32 | }; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/comma-style.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable comma-style */ 3 | /*eslint comma-style: ["error", "last"]*/ 4 | function incorrect() { 5 | var foo = 1 6 | , 7 | bar = 2; 8 | 9 | var foo = 1 10 | , bar = 2; 11 | 12 | var foo = ["apples" 13 | , "oranges"]; 14 | 15 | function bar() { 16 | return { 17 | "a": 1 18 | ,"b:": 2 19 | }; 20 | } 21 | } 22 | 23 | function correct() { 24 | var foo = 1, bar = 2; 25 | 26 | var foo = 1, 27 | bar = 2; 28 | 29 | var foo = ["apples", 30 | "oranges"]; 31 | 32 | function bar() { 33 | return { 34 | "a": 1, 35 | "b:": 2 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/computed-property-spacing-always.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable computed-property-spacing */ 3 | /*eslint computed-property-spacing: ["error", "always"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | obj[foo] 8 | var x = {[b]: a} 9 | obj[ foo] 10 | obj['foo' ] 11 | obj[foo[ bar ]] 12 | var x = {[ b]: a} 13 | const { [a]: someProp } = obj; 14 | ({ [b ]: anotherProp } = anotherObj); 15 | } 16 | 17 | function correct() { 18 | /*eslint-env es6*/ 19 | 20 | obj[ foo ] 21 | obj[ 'foo' ] 22 | var x = {[ b ]: a} 23 | obj[ foo[ bar ] ] 24 | const { [ a ]: someProp } = obj; 25 | ({ [ b ]: anotherProp } = anotherObj); 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/computed-property-spacing-enforceForClassMembersTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable computed-property-spacing */ 3 | /*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | class Foo { 8 | [a ]() {} 9 | get [b ]() {} 10 | set [b ](value) {} 11 | } 12 | 13 | const Bar = class { 14 | [ a](){} 15 | static [ b]() {} 16 | static get [ c ]() {} 17 | static set [ c ](value) {} 18 | } 19 | } 20 | 21 | function correct() { 22 | /*eslint-env es6*/ 23 | 24 | class Foo { 25 | [a]() {} 26 | get [b]() {} 27 | set [b](value) {} 28 | } 29 | 30 | const Bar = class { 31 | [a](){} 32 | static [b]() {} 33 | static get [c]() {} 34 | static set [c](value) {} 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/computed-property-spacing-never-enforceForClassMembersFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable computed-property-spacing */ 3 | /*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": false }]*/ 4 | function correct() { 5 | /*eslint-env es6*/ 6 | 7 | class Foo { 8 | [a ]() {} 9 | get [b ]() {} 10 | set [b ](value) {} 11 | } 12 | 13 | const Bar = class { 14 | [ a](){} 15 | static [ b]() {} 16 | static get [ c ]() {} 17 | static set [ c ](value) {} 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/computed-property-spacing.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable computed-property-spacing */ 3 | /*eslint computed-property-spacing: ["error", "never"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | obj[foo ] 8 | obj[ 'foo'] 9 | var x = {[ b ]: a} 10 | obj[foo[ bar ]] 11 | 12 | const { [ a ]: someProp } = obj; 13 | ({ [ b ]: anotherProp } = anotherObj); 14 | } 15 | 16 | function correct() { 17 | /*eslint-env es6*/ 18 | 19 | obj[foo] 20 | obj['foo'] 21 | var x = {[b]: a} 22 | obj[foo[bar]] 23 | 24 | const { [a]: someProp } = obj; 25 | ({ [b]: anotherProp } = anotherObj); 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/multiline-comment-style-bareBlock.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable multiline-comment-style */ 3 | /* eslint multiline-comment-style: ["error", "bare-block"] */ 4 | function incorrect() { 5 | // this line 6 | // calls foo() 7 | foo(); 8 | 9 | /* 10 | * this line 11 | * calls foo() 12 | */ 13 | foo(); 14 | } 15 | 16 | function correct() { 17 | /* this line 18 | calls foo() */ 19 | foo(); 20 | } 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/multiline-comment-style-separateLines.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable multiline-comment-style */ 3 | /* eslint multiline-comment-style: ["error", "separate-lines"] */ 4 | function incorrect() { 5 | /* This line 6 | calls foo() */ 7 | foo(); 8 | 9 | /* 10 | * This line 11 | * calls foo() 12 | */ 13 | foo(); 14 | } 15 | 16 | function correct() { 17 | // This line 18 | // calls foo() 19 | foo(); 20 | } 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/multiline-comment-style.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable multiline-comment-style */ 3 | /* eslint multiline-comment-style: ["error", "starred-block"] */ 4 | function incorrect() { 5 | // this line 6 | // calls foo() 7 | foo(); 8 | 9 | /* this line 10 | calls foo() */ 11 | foo(); 12 | 13 | /* this comment 14 | * is missing a newline after /* 15 | */ 16 | 17 | /* 18 | * this comment 19 | * is missing a newline at the end */ 20 | 21 | /* 22 | * the star in this line should have a space before it 23 | */ 24 | 25 | /* 26 | * the star on the following line should have a space before it 27 | */ 28 | } 29 | 30 | function correct() { 31 | /* 32 | * this line 33 | * calls foo() 34 | */ 35 | foo(); 36 | 37 | // single-line comment 38 | } 39 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/no-confusing-arrow-allowParensFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-confusing-arrow */ 3 | /*eslint no-confusing-arrow: ["error", {"allowParens": false}]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | var x = a => (1 ? 2 : 3); 7 | var x = (a) => (1 ? 2 : 3); 8 | } 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/no-confusing-arrow-onlyOneSimpleParamTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-confusing-arrow */ 3 | /*eslint no-confusing-arrow: ["error", {"onlyOneSimpleParam": true}]*/ 4 | function correct() { 5 | /*eslint-env es6*/ 6 | () => 1 ? 2 : 3; 7 | (a, b) => 1 ? 2 : 3; 8 | (a = b) => 1 ? 2 : 3; 9 | ({ a }) => 1 ? 2 : 3; 10 | ([a]) => 1 ? 2 : 3; 11 | (...a) => 1 ? 2 : 3; 12 | } 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/no-confusing-arrow.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-confusing-arrow */ 3 | /*eslint no-confusing-arrow: "error"*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | var x = a => 1 ? 2 : 3; 8 | var x = (a) => 1 ? 2 : 3; 9 | } 10 | 11 | function correct() { 12 | /*eslint-env es6*/ 13 | var x = a => (1 ? 2 : 3); 14 | var x = (a) => (1 ? 2 : 3); 15 | var x = (a) => { 16 | return 1 ? 2 : 3; 17 | }; 18 | var x = a => { return 1 ? 2 : 3; }; 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/no-extra-semi.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-semi */ 3 | /*eslint no-extra-semi: "error"*/ 4 | function incorrect() { 5 | var x = 5;; 6 | 7 | function foo() { 8 | // code 9 | }; 10 | 11 | class C { 12 | field;; 13 | 14 | method() { 15 | // code 16 | }; 17 | 18 | static { 19 | // code 20 | }; 21 | }; 22 | } 23 | 24 | function correct() { 25 | var x = 5; 26 | 27 | function foo() { 28 | // code 29 | } 30 | 31 | var bar = function() { 32 | // code 33 | }; 34 | 35 | class C { 36 | field; 37 | 38 | method() { 39 | // code 40 | } 41 | 42 | static { 43 | // code 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/no-floating-decimal.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-floating-decimal */ 3 | /*eslint no-floating-decimal: "error"*/ 4 | function incorrect() { 5 | var num = .5; 6 | var num = 2.; 7 | var num = -.7; 8 | } 9 | 10 | function correct() { 11 | var num = 0.5; 12 | var num = 2.0; 13 | var num = -0.7; 14 | } 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/one-var-declaration-per-line-always.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var-declaration-per-line: ["error", "always"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | var a, b; 8 | 9 | let a, b = 0; 10 | 11 | const a = 0, b = 0; 12 | } 13 | 14 | function correct() { 15 | /*eslint-env es6*/ 16 | 17 | var a, 18 | b; 19 | 20 | let a, 21 | b = 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/one-var-declaration-per-line.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var-declaration-per-line: ["error", "initializations"]*/ 4 | function incorrect() { 5 | /*eslint-env es6*/ 6 | 7 | var a, b, c = 0; 8 | 9 | let a, 10 | b = 0, c; 11 | } 12 | 13 | function correct() { 14 | /*eslint-env es6*/ 15 | 16 | var a, b; 17 | 18 | let a, 19 | b; 20 | 21 | let a, 22 | b = 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-asNeeded-keywordsTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "as-needed", { "keywords": true }]*/ 4 | function incorrect() { 5 | var x = { 6 | while: 1, 7 | volatile: "foo" 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-asNeeded-numbersTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "as-needed", { "numbers": true }]*/ 4 | function incorrect() { 5 | var x = { 6 | 100: 1 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-asNeeded-unnecessaryFalse.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "as-needed", { "keywords": true, "unnecessary": false }]*/ 4 | function correct() { 5 | var x = { 6 | "while": 1, 7 | "foo": "bar" // Would normally have caused a warning 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-asNeeded.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "as-needed"]*/ 4 | function incorrect() { 5 | var object = { 6 | "a": 0, 7 | "0": 0, 8 | "true": 0, 9 | "null": 0 10 | }; 11 | } 12 | 13 | function correct() { 14 | /*eslint-env es6*/ 15 | 16 | var object1 = { 17 | "a-b": 0, 18 | "0x0": 0, 19 | "1e2": 0 20 | }; 21 | 22 | var object2 = { 23 | foo: 'bar', 24 | baz: 42, 25 | true: 0, 26 | 0: 0, 27 | 'qux-lorem': true 28 | }; 29 | 30 | var object3 = { 31 | foo() { 32 | return; 33 | } 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-consistent.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "consistent"]*/ 4 | function incorrect() { 5 | var object1 = { 6 | foo: "bar", 7 | "baz": 42, 8 | "qux-lorem": true 9 | }; 10 | 11 | var object2 = { 12 | 'foo': 'bar', 13 | baz: 42 14 | }; 15 | } 16 | 17 | function correct() { 18 | var object1 = { 19 | "foo": "bar", 20 | "baz": 42, 21 | "qux-lorem": true 22 | }; 23 | 24 | var object2 = { 25 | 'foo': 'bar', 26 | 'baz': 42 27 | }; 28 | 29 | var object3 = { 30 | foo: 'bar', 31 | baz: 42 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-consistentAsNeeded-keywordsTrue.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | function incorrect() { 4 | /*eslint quote-props: ["error", "consistent-as-needed", { "keywords": true }]*/ 5 | 6 | var x = { 7 | "prop": 1, 8 | "bar": "foo" 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props-consistentAsNeeded.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "consistent-as-needed"]*/ 4 | function incorrect() { 5 | var object1 = { 6 | foo: "bar", 7 | "baz": 42, 8 | "qux-lorem": true 9 | }; 10 | 11 | var object2 = { 12 | 'foo': 'bar', 13 | 'baz': 42 14 | }; 15 | } 16 | 17 | function correct() { 18 | var object1 = { 19 | "foo": "bar", 20 | "baz": 42, 21 | "qux-lorem": true 22 | }; 23 | 24 | var object2 = { 25 | foo: 'bar', 26 | baz: 42 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/quote-props.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable quote-props */ 3 | /*eslint quote-props: ["error", "always"]*/ 4 | function incorrect() { 5 | var object = { 6 | foo: "bar", 7 | baz: 42 8 | }; 9 | } 10 | 11 | function correct() { 12 | /*eslint-env es6*/ 13 | 14 | var object1 = { 15 | "foo": "bar", 16 | "baz": 42, 17 | "qux-lorem": true 18 | }; 19 | 20 | var object2 = { 21 | 'foo': 'bar', 22 | 'baz': 42, 23 | 'qux-lorem': true 24 | }; 25 | 26 | var object3 = { 27 | foo() { 28 | return; 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/spaced-comment-always-marker.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable spaced-comment */ 3 | /* eslint spaced-comment: ["error", "always", { "markers": ["/", "!<", "global"] }] */ 4 | function incorrect() { 5 | ///This is a comment with a marker but without whitespace 6 | 7 | /*! This is a comment with a marker but without whitespace at the end*/ 8 | } 9 | 10 | function correct() { 11 | /// This is a comment with a marker 12 | 13 | /*global ABC*/ 14 | } 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/spaced-comment-exception.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable spaced-comment */ 3 | /* eslint spaced-comment: ["error", "always", { "exceptions": ["-", "+", "*", "-+"], "block": { "exceptions": ["-", "*", "-+"] }, "line": { "exceptions": ["-+", "-"] } }] */ 4 | function incorrect() { 5 | //-------------- 6 | // Comment block 7 | //-------------- 8 | 9 | //------++++++++ 10 | // Comment block 11 | //------++++++++ 12 | 13 | /*------++++++++*/ 14 | /* Comment block */ 15 | /*------++++++++*/ 16 | 17 | /*-+-+-+-+-+-+-+*/ 18 | // Comment block 19 | /*-+-+-+-+-+-+-+*/ 20 | 21 | /******** COMMENT *******/ 22 | } 23 | 24 | function correct() { 25 | //-------------- 26 | // Comment block 27 | //-------------- 28 | 29 | //-------------- 30 | // Comment block 31 | //-------------- 32 | 33 | /**************** 34 | * Comment block 35 | ****************/ 36 | 37 | //-+-+-+-+-+-+-+ 38 | // Comment block 39 | //-+-+-+-+-+-+-+ 40 | 41 | /*-+-+-+-+-+-+-+*/ 42 | // Comment block 43 | /*-+-+-+-+-+-+-+*/ 44 | 45 | /*-+-+-+-+-+-+-+*/ 46 | // Comment block 47 | /*-+-+-+-+-+-+-+*/ 48 | 49 | /***************/ 50 | 51 | /******** 52 | COMMENT 53 | *******/ 54 | } 55 | -------------------------------------------------------------------------------- /tests/javascript/fixes/deprecated/spaced-comment-never-marker.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /*eslint-enable spaced-comment*/ 3 | /*eslint spaced-comment: ["error", "never", { "markers": ["!<"], "block": { "markers": ["!", "!<"], "balanced": true } }]*/ 4 | function incorrect() { 5 | /*!This is a comment with a marker but with whitespace at the end */ 6 | } 7 | 8 | function correct() { 9 | //! a &&= b 5 | if (!a) a = b // <=> a ||= b 6 | 7 | if (a == null) a = b // <=> a ??= b 8 | if (a === null || a === undefined) a = b // <=> a ??= b 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/logical-assignment-operators-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable logical-assignment-operators */ 3 | /*eslint logical-assignment-operators: ["error", "always"]*/ 4 | a = a || b 5 | a = a && b 6 | a = a ?? b 7 | a || (a = b) 8 | a && (a = b) 9 | a ?? (a = b) 10 | a = a || b || c 11 | a = a && b && c 12 | a = a ?? b ?? c 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/logical-assignment-operators-never-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable logical-assignment-operators */ 3 | /*eslint logical-assignment-operators: ["error", "never"]*/ 4 | a = a || b 5 | a = a && b 6 | a = a ?? b 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/logical-assignment-operators-never-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable logical-assignment-operators */ 3 | /*eslint logical-assignment-operators: ["error", "never"]*/ 4 | a ||= b 5 | a &&= b 6 | a ??= b 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-div-regex-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-div-regex */ 3 | /*eslint no-div-regex: "error"*/ 4 | function bar() { return /[=]foo/; } 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-div-regex-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-div-regex */ 3 | /*eslint no-div-regex: "error"*/ 4 | function bar() { return /=foo/; } 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-else-return-allowElseIfFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-else-return */ 3 | /*eslint no-else-return: ["error", {allowElseIf: false}]*/ 4 | function foo() { 5 | if (error) { 6 | return 'It failed'; 7 | } 8 | 9 | if (loading) { 10 | return "It's still loading"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-else-return-allowElseIfFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-else-return */ 3 | /*eslint no-else-return: ["error", {allowElseIf: false}]*/ 4 | function foo() { 5 | if (error) { 6 | return 'It failed'; 7 | } else if (loading) { 8 | return "It's still loading"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-else-return-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-else-return */ 3 | /*eslint no-else-return: "error"*/ 4 | function foo() { 5 | if (x) { 6 | return y; 7 | } 8 | 9 | return z; 10 | } 11 | 12 | function foo() { 13 | if (x) { 14 | return y; 15 | } else if (z) { 16 | var t = "foo"; 17 | } else { 18 | return w; 19 | } 20 | } 21 | 22 | function foo() { 23 | if (x) { 24 | if (z) { 25 | return y; 26 | } 27 | } else { 28 | return z; 29 | } 30 | } 31 | 32 | function foo() { 33 | if (error) { 34 | return 'It failed'; 35 | } else if (loading) { 36 | return "It's still loading"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-else-return-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-else-return */ 3 | /*eslint no-else-return: "error"*/ 4 | function foo() { 5 | if (x) { 6 | return y; 7 | } else { 8 | return z; 9 | } 10 | } 11 | 12 | function foo() { 13 | if (x) { 14 | return y; 15 | } else if (z) { 16 | return w; 17 | } else { 18 | return t; 19 | } 20 | } 21 | 22 | function foo() { 23 | if (x) { 24 | return y; 25 | } else { 26 | var t = "foo"; 27 | } 28 | 29 | return t; 30 | } 31 | 32 | function foo() { 33 | if (error) { 34 | return 'It failed'; 35 | } else { 36 | if (loading) { 37 | return "It's still loading"; 38 | } 39 | } 40 | } 41 | 42 | // Two warnings for nested occurrences 43 | function foo() { 44 | if (x) { 45 | if (y) { 46 | return y; 47 | } else { 48 | return x; 49 | } 50 | } else { 51 | return z; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-bind-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-bind */ 3 | /*eslint no-extra-bind: "error"*/ 4 | var x = function () { 5 | this.foo(); 6 | }.bind(bar); 7 | 8 | var x = function (a) { 9 | return a + 1; 10 | }.bind(foo, bar); 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-bind-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-bind */ 3 | /*eslint no-extra-bind: "error"*/ 4 | var x = function () { 5 | foo(); 6 | }.bind(bar); 7 | 8 | var x = (() => { 9 | foo(); 10 | }).bind(bar); 11 | 12 | var x = (() => { 13 | this.foo(); 14 | }).bind(bar); 15 | 16 | var x = function () { 17 | (function () { 18 | this.foo(); 19 | }()); 20 | }.bind(bar); 21 | 22 | var x = function () { 23 | function foo() { 24 | this.bar(); 25 | } 26 | }.bind(baz); 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-boolean-cast-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-boolean-cast */ 3 | /*eslint no-extra-boolean-cast: "error"*/ 4 | var foo = !!bar; 5 | var foo = Boolean(bar); 6 | 7 | function foo() { 8 | return !!bar; 9 | } 10 | 11 | var foo = bar ? !!baz : !!bat; 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-boolean-cast-enforceForLogicalOperandsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-boolean-cast */ 3 | /*eslint no-extra-boolean-cast: ["error", {"enforceForLogicalOperands": true}]*/ 4 | if (foo || bar) { 5 | //... 6 | } 7 | 8 | while (foo && bar) { 9 | //... 10 | } 11 | 12 | if ((foo || bar) && baz) { 13 | //... 14 | } 15 | 16 | foo && bar ? baz : bat 17 | 18 | var foo = new Boolean(bar || baz) 19 | 20 | var foo = !!bar || baz; 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-boolean-cast-enforceForLogicalOperandsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-boolean-cast */ 3 | /*eslint no-extra-boolean-cast: ["error", {"enforceForLogicalOperands": true}]*/ 4 | if (!!foo || bar) { 5 | //... 6 | } 7 | 8 | while (!!foo && bar) { 9 | //... 10 | } 11 | 12 | if ((!!foo || bar) && baz) { 13 | //... 14 | } 15 | 16 | foo && Boolean(bar) ? baz : bat 17 | 18 | var foo = new Boolean(!!bar || baz) 19 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-boolean-cast-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-boolean-cast */ 3 | /*eslint no-extra-boolean-cast: "error"*/ 4 | var foo = !!!bar; 5 | 6 | var foo = !!bar ? baz : bat; 7 | 8 | var foo = Boolean(!!bar); 9 | 10 | var foo = new Boolean(!!bar); 11 | 12 | if (!!foo) { 13 | // ... 14 | } 15 | 16 | if (Boolean(foo)) { 17 | // ... 18 | } 19 | 20 | while (!!foo) { 21 | // ... 22 | } 23 | 24 | do { 25 | // ... 26 | } while (Boolean(foo)); 27 | 28 | for (; !!foo; ) { 29 | // ... 30 | } 31 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-label-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-label */ 3 | /*eslint no-extra-label: "error"*/ 4 | while (a) { 5 | break; 6 | } 7 | 8 | for (let i = 0; i < 10; ++i) { 9 | break; 10 | } 11 | 12 | switch (a) { 13 | case 0: 14 | break; 15 | } 16 | 17 | A: { 18 | break A; 19 | } 20 | 21 | B: while (a) { 22 | while (b) { 23 | break B; 24 | } 25 | } 26 | 27 | C: switch (a) { 28 | case 0: 29 | while (b) { 30 | break C; 31 | } 32 | break; 33 | } 34 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-extra-label-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-extra-label */ 3 | /*eslint no-extra-label: "error"*/ 4 | A: while (a) { 5 | break A; 6 | } 7 | 8 | B: for (let i = 0; i < 10; ++i) { 9 | break B; 10 | } 11 | 12 | C: switch (a) { 13 | case 0: 14 | break C; 15 | } 16 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-allow-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: [2, { "allow": ["!!", "~"] } ]*/ 4 | var b = !!foo; 5 | var b = ~foo.indexOf("."); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-boolean-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var b = Boolean(foo); 5 | var b = foo.indexOf(".") !== -1; 6 | 7 | var n = ~foo; // This is a just bitwise not. 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-boolean-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var b = !!foo; 5 | var b = ~foo.indexOf("."); 6 | // bitwise not is incorrect only with `indexOf`/`lastIndexOf` method calling. 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-disallowTemplateShorthandFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": false }]*/ 4 | var s = `${foo}`; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-disallowTemplateShorthandTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ 4 | var s = String(foo); 5 | 6 | var s = `a${foo}`; 7 | 8 | var s = `${foo}b`; 9 | 10 | var s = `${foo}${bar}`; 11 | 12 | var s = tag`${foo}`; 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-disallowTemplateShorthandTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ 4 | var s = `${foo}`; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-number-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var n = Number(foo); 5 | var n = parseFloat(foo); 6 | var n = parseInt(foo, 10); 7 | 8 | var n = foo * 1/4; // `* 1` is allowed when followed by the `/` operator 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-number-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var n = +foo; 5 | var n = -(-foo); 6 | var n = foo - 0; 7 | var n = 1 * foo; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-string-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var s = String(foo); 5 | foo = String(foo); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-implicit-coercion-string-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var s = "" + foo; 5 | var s = `` + foo; 6 | foo += ""; 7 | foo += ``; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-lonely-if-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-lonely-if */ 3 | /*eslint no-lonely-if: "error"*/ 4 | if (condition) { 5 | // ... 6 | } else if (anotherCondition) { 7 | // ... 8 | } 9 | 10 | if (condition) { 11 | // ... 12 | } else if (anotherCondition) { 13 | // ... 14 | } else { 15 | // ... 16 | } 17 | 18 | if (condition) { 19 | // ... 20 | } else { 21 | if (anotherCondition) { 22 | // ... 23 | } 24 | doSomething(); 25 | } 26 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-lonely-if-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-lonely-if */ 3 | /*eslint no-lonely-if: "error"*/ 4 | if (condition) { 5 | // ... 6 | } else { 7 | if (anotherCondition) { 8 | // ... 9 | } 10 | } 11 | 12 | if (condition) { 13 | // ... 14 | } else { 15 | if (anotherCondition) { 16 | // ... 17 | } else { 18 | // ... 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-regex-spaces-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-regex-spaces */ 3 | /*eslint no-regex-spaces: "error"*/ 4 | var re = /foo {3}bar/; 5 | var re = new RegExp("foo {3}bar"); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-regex-spaces-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-regex-spaces */ 3 | /*eslint no-regex-spaces: "error"*/ 4 | var re = /foo bar/; 5 | var re = new RegExp("foo bar"); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-undef-init-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-undef-init */ 3 | /*eslint no-undef-init: "error"*/ 4 | var foo; 5 | let bar; 6 | 7 | const foo = undefined; 8 | 9 | let { bar = undefined } = baz; 10 | 11 | [quux = undefined] = quuux; 12 | 13 | (foo = undefined) => {}; 14 | 15 | class Foo { 16 | bar = undefined; 17 | } 18 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-undef-init-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-undef-init */ 3 | /*eslint no-undef-init: "error"*/ 4 | var foo = undefined; 5 | let bar = undefined; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-unneeded-ternary-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unneeded-ternary */ 3 | /*eslint no-unneeded-ternary: "error"*/ 4 | var a = x === 2 ? "Yes" : "No"; 5 | 6 | var a = x !== false; 7 | 8 | var a = x ? "Yes" : "No"; 9 | 10 | var a = x ? y : x; 11 | 12 | f(x ? x : 1); // default assignment - would be disallowed if defaultAssignment option set to false. See option details below. 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-unneeded-ternary-defaultAssignmentFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unneeded-ternary */ 3 | /*eslint no-unneeded-ternary: ["error", { "defaultAssignment": false }]*/ 4 | var a = x ? x : 1; 5 | 6 | f(x ? x : 1); 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-unneeded-ternary-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unneeded-ternary */ 3 | /*eslint no-unneeded-ternary: "error"*/ 4 | var a = x === 2 ? true : false; 5 | 6 | var a = x ? true : false; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-unused-labels-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unused-labels */ 3 | /*eslint no-unused-labels: "error"*/ 4 | A: { 5 | if (foo()) { 6 | break A; 7 | } 8 | bar(); 9 | } 10 | 11 | B: 12 | for (let i = 0; i < 10; ++i) { 13 | if (foo()) { 14 | break B; 15 | } 16 | bar(); 17 | } 18 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-unused-labels-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unused-labels */ 3 | /*eslint no-unused-labels: "error"*/ 4 | A: var foo = 0; 5 | 6 | B: { 7 | foo(); 8 | } 9 | 10 | C: 11 | for (let i = 0; i < 10; ++i) { 12 | foo(); 13 | } 14 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-computed-key-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-computed-key */ 3 | /*eslint no-useless-computed-key: "error"*/ 4 | var c = { 'a': 0 }; 5 | var c = { 0: 0 }; 6 | var a = { x() {} }; 7 | var c = { a: 0 }; 8 | var c = { '0+1,234': 0 }; 9 | 10 | class Foo { 11 | "foo" = "bar"; 12 | 13 | 0() {} 14 | 'a'() {} 15 | get 'b'() {} 16 | set 'c'(value) {} 17 | 18 | static "foo" = "bar"; 19 | 20 | static 'a'() {} 21 | } 22 | 23 | var c = { 24 | "__proto__": foo, // defines object's prototype 25 | 26 | ["__proto__"]: bar // defines a property named "__proto__" 27 | }; 28 | 29 | class Foo { 30 | ["constructor"]; // instance field named "constructor" 31 | 32 | "constructor"() {} // the constructor of this class 33 | 34 | ["constructor"]() {} // method named "constructor" 35 | 36 | static ["constructor"]; // static field named "constructor" 37 | 38 | static ["prototype"]; // runtime error, it would be a parsing error without `[]` 39 | } 40 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-computed-key-enforceForClassMembersFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-computed-key */ 3 | /*eslint no-useless-computed-key: ["error", { "enforceForClassMembers": false }]*/ 4 | class SomeClass { 5 | ["foo"] = "bar"; 6 | [42] = "baz"; 7 | 8 | ['a']() {} 9 | get ['b']() {} 10 | set ['c'](value) {} 11 | 12 | static ["foo"] = "bar"; 13 | static ['baz']() {} 14 | } 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-computed-key-enforceForClassMembersFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-computed-key */ 3 | /*eslint no-useless-computed-key: ["error", { "enforceForClassMembers": false }]*/ 4 | const obj = { 5 | ["foo"]: "bar", 6 | [42]: "baz", 7 | 8 | ['a']() {}, 9 | get ['b']() {}, 10 | set ['c'](value) {} 11 | }; 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-computed-key-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-computed-key */ 3 | /*eslint no-useless-computed-key: "error"*/ 4 | var a = { ['0']: 0 }; 5 | var a = { ['0+1,234']: 0 }; 6 | var a = { [0]: 0 }; 7 | var a = { ['x']: 0 }; 8 | var a = { ['x']() {} }; 9 | 10 | class Foo { 11 | ["foo"] = "bar"; 12 | 13 | [0]() {} 14 | ['a']() {} 15 | get ['b']() {} 16 | set ['c'](value) {} 17 | 18 | static ["foo"] = "bar"; 19 | 20 | static ['a']() {} 21 | } 22 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-rename-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-rename */ 3 | /*eslint no-useless-rename: "error"*/ 4 | import * as foo1 from "foo"; 5 | import { foo2 } from "bar"; 6 | import { foo as bar1 } from "baz"; 7 | 8 | export { foo }; 9 | export { foo as bar1 }; 10 | export { foo as bar3 } from "foo"; 11 | 12 | let { foo } = bar; 13 | let { foo: bar } = baz; 14 | let { [qux]: qux } = bar; 15 | 16 | function foo3({ bar }) {} 17 | function foo4({ bar: baz }) {} 18 | 19 | ({ foo }) => {} 20 | ({ foo: bar }) => {} 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-rename-ignoreDestructuringTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-rename */ 3 | /*eslint no-useless-rename: ["error", { ignoreDestructuring: true }]*/ 4 | let { foo: foo } = bar; 5 | function foo({ bar: bar }) {} 6 | ({ foo: foo }) => {} 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-rename-ignoreExportTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-rename */ 3 | /*eslint no-useless-rename: ["error", { ignoreExport: true }]*/ 4 | const foo = 1; 5 | export { foo as foo }; 6 | export { bar as bar } from "bar"; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-rename-ignoreImportTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-rename */ 3 | /*eslint no-useless-rename: ["error", { ignoreImport: true }]*/ 4 | import { foo as foo } from "bar"; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-rename-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-rename */ 3 | /*eslint no-useless-rename: "error"*/ 4 | import { foo1 as foo1 } from "bar"; 5 | import { "foo2" as foo2 } from "bar"; 6 | export { foo1 as foo1 }; 7 | export { foo2 as "foo2" }; 8 | export { foo3 as foo3 } from "bar"; 9 | export { "foo4" as "foo4" } from "bar"; 10 | let { foo3: foo3 } = bar; 11 | let { 'foo4': foo4 } = bar; 12 | function foo({ bar: bar }) {} 13 | ({ foo: foo }) => {} 14 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-return-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-return */ 3 | /* eslint no-useless-return: "error" */ 4 | var foo = function() { return 5; } 5 | 6 | var foo = function() { 7 | return doSomething(); 8 | } 9 | 10 | var foo = function() { 11 | if (condition) { 12 | bar(); 13 | return; 14 | } else { 15 | baz(); 16 | } 17 | qux(); 18 | } 19 | 20 | var foo = function() { 21 | switch (bar) { 22 | case 1: 23 | doSomething(); 24 | return; 25 | default: 26 | doSomethingElse(); 27 | } 28 | } 29 | 30 | var foo = function() { 31 | for (const foo of bar) { 32 | return; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-useless-return-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-return */ 3 | /* eslint no-useless-return: "error" */ 4 | var foo = function() { return; } 5 | 6 | var foo = function() { 7 | doSomething(); 8 | return; 9 | } 10 | 11 | var foo = function() { 12 | if (condition) { 13 | bar(); 14 | return; 15 | } else { 16 | baz(); 17 | } 18 | } 19 | 20 | var foo = function() { 21 | switch (bar) { 22 | case 1: 23 | doSomething(); 24 | default: 25 | doSomethingElse(); 26 | return; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-var-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-var */ 3 | /*eslint no-var: "error"*/ 4 | let x = "y"; 5 | const CONFIG = {}; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/no-var-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-var */ 3 | /*eslint no-var: "error"*/ 4 | var x = "y"; 5 | var CONFIG = {}; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-avoidExplicitReturnArrowsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/ 4 | var foo = { 5 | foo(bar, baz) { 6 | return bar + baz; 7 | }, 8 | 9 | qux: foobar => foobar * 2 10 | }; 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-avoidExplicitReturnArrowsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/ 4 | var foo = { 5 | foo: (bar, baz) => { 6 | return bar + baz; 7 | }, 8 | 9 | qux: (foobar) => { 10 | return foobar * 2; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-avoidQuotesTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/ 4 | var foo = { 5 | "bar-baz": function() {}, 6 | "qux": qux 7 | }; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-avoidQuotesTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/ 4 | var foo = { 5 | "bar-baz"() {} 6 | }; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-consistent-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: [2, "consistent"]*/ 4 | var foo = { 5 | a: a, 6 | b: "foo" 7 | }; 8 | 9 | var bar = { 10 | a, 11 | b, 12 | }; 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-consistent-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: [2, "consistent"]*/ 4 | var foo = { 5 | a, 6 | b: "foo", 7 | }; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-consistentAsNeeded-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: [2, "consistent-as-needed"]*/ 4 | var foo = { 5 | a: a, 6 | b: b, 7 | }; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-ignoreConstructorsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/ 4 | var foo = { 5 | ConstructorFunction: function() {} 6 | }; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/object-shorthand-methodsIgnorePattern-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable object-shorthand */ 3 | /*eslint object-shorthand: ["error", "always", { "methodsIgnorePattern": "^bar$" }]*/ 4 | var foo = { 5 | bar: function() {} 6 | }; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-consecutive-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "consecutive"]*/ 4 | function foo1() { 5 | var bar, 6 | baz; 7 | } 8 | 9 | function foo2(){ 10 | var bar = 1, 11 | baz = 2; 12 | 13 | qux(); 14 | 15 | var qux = 3, 16 | quux; 17 | } 18 | 19 | class C { 20 | static { 21 | var foo, bar; 22 | let baz, qux; 23 | doSomething(); 24 | let quux; 25 | var quuux; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-consecutive-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "consecutive"]*/ 4 | function foo1() { 5 | var bar; 6 | var baz; 7 | } 8 | 9 | function foo2(){ 10 | var bar = 1; 11 | var baz = 2; 12 | 13 | qux(); 14 | 15 | var qux = 3; 16 | var quux; 17 | } 18 | 19 | class C { 20 | static { 21 | var foo; 22 | var bar; 23 | let baz; 24 | let qux; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "always"]*/ 4 | function foo1() { 5 | var bar, 6 | baz; 7 | let qux, 8 | norf; 9 | } 10 | 11 | function foo2(){ 12 | const bar = true, 13 | baz = false; 14 | let qux, 15 | norf; 16 | } 17 | 18 | function foo3() { 19 | var bar, 20 | qux; 21 | 22 | if (baz) { 23 | qux = true; 24 | } 25 | } 26 | 27 | function foo4(){ 28 | let bar; 29 | 30 | if (baz) { 31 | let qux; 32 | } 33 | } 34 | 35 | class C { 36 | static { 37 | var foo, bar; 38 | } 39 | 40 | static { 41 | var foo, baz; 42 | if (bar) { 43 | baz = true; 44 | } 45 | } 46 | 47 | static { 48 | let foo, bar; 49 | } 50 | 51 | static { 52 | let foo; 53 | if (bar) { 54 | let baz; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "always"]*/ 4 | function foo1() { 5 | var bar; 6 | var baz; 7 | let qux; 8 | let norf; 9 | } 10 | 11 | function foo2(){ 12 | const bar = false; 13 | const baz = true; 14 | let qux; 15 | let norf; 16 | } 17 | 18 | function foo3() { 19 | var bar; 20 | 21 | if (baz) { 22 | var qux = true; 23 | } 24 | } 25 | 26 | class C { 27 | static { 28 | var foo; 29 | var bar; 30 | } 31 | 32 | static { 33 | var foo; 34 | if (bar) { 35 | var baz = true; 36 | } 37 | } 38 | 39 | static { 40 | let foo; 41 | let bar; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedAlways-uninitializedNever-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/ 4 | function foo() { 5 | var a; 6 | var b; 7 | var c; 8 | var foo = true, 9 | bar = false; 10 | } 11 | 12 | for (let z of foo) { 13 | doSomething(z); 14 | } 15 | 16 | let z; 17 | for (z of foo) { 18 | doSomething(z); 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedAlways-uninitializedNever-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "always", "uninitialized": "never" }]*/ 4 | function foo() { 5 | var a, b, c; 6 | var foo = true; 7 | var bar = false; 8 | } 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedConsecutive-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "consecutive" }]*/ 4 | function foo() { 5 | var a = 1, 6 | b = 2; 7 | 8 | foo(); 9 | 10 | var c = 3, 11 | d = 4; 12 | } 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedConsecutive-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "consecutive" }]*/ 4 | function foo() { 5 | var a = 1; 6 | var b = 2; 7 | 8 | foo(); 9 | 10 | var c = 3; 11 | var d = 4; 12 | } 13 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedConsecutive-uninitializedNever-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "consecutive", "uninitialized": "never" }]*/ 4 | function foo() { 5 | var a = 1, 6 | b = 2; 7 | var c; 8 | var d; 9 | var e = 3, 10 | f = 4; 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedConsecutive-uninitializedNever-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "consecutive", "uninitialized": "never" }]*/ 4 | function foo() { 5 | var a = 1; 6 | var b = 2; 7 | var c, 8 | d; 9 | var e = 3; 10 | var f = 4; 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedNever-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "never" }]*/ 4 | function foo() { 5 | var foo = true; 6 | var bar = false; 7 | var a, b, c; // Uninitialized variables are ignored 8 | } 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-initializedNever-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { "initialized": "never" }]*/ 4 | function foo() { 5 | var foo = true, 6 | bar = false; 7 | } 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-never-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "never"]*/ 4 | function foo1() { 5 | var bar; 6 | var baz; 7 | } 8 | 9 | function foo2() { 10 | var bar; 11 | 12 | if (baz) { 13 | var qux = true; 14 | } 15 | } 16 | 17 | function foo3() { 18 | let bar; 19 | 20 | if (baz) { 21 | let qux = true; 22 | } 23 | } 24 | 25 | class C { 26 | static { 27 | var foo; 28 | var bar; 29 | let baz; 30 | let qux; 31 | } 32 | } 33 | 34 | // declarations with multiple variables are allowed in for-loop initializers 35 | for (var i = 0, len = arr.length; i < len; i++) { 36 | doSomething(arr[i]); 37 | } 38 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-never-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", "never"]*/ 4 | function foo1() { 5 | var bar, 6 | baz; 7 | const qux = true, 8 | foobar = false; 9 | } 10 | 11 | function foo2() { 12 | var bar, 13 | qux; 14 | 15 | if (baz) { 16 | qux = true; 17 | } 18 | } 19 | 20 | function foo3(){ 21 | let bar = true, 22 | baz = false; 23 | } 24 | 25 | class C { 26 | static { 27 | var foo, bar; 28 | let baz, qux; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-separateRequiresTrue-varAlways-correct-1.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { separateRequires: true, var: "always" }]*/ 4 | var foo = require("foo"); 5 | var bar = "bar"; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-separateRequiresTrue-varAlways-correct-2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { separateRequires: true, var: "always" }]*/ 4 | var foo = require("foo"), 5 | bar = require("bar"); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-separateRequiresTrue-varAlways-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { separateRequires: true, var: "always" }]*/ 4 | var foo = require("foo"), 5 | bar = "bar"; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varAlways-letNever-constNever-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/ 4 | function foo1() { 5 | var bar, 6 | baz; 7 | let qux; 8 | let norf; 9 | } 10 | 11 | function foo2() { 12 | const bar = 1; 13 | const baz = 2; 14 | let qux; 15 | let norf; 16 | } 17 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varAlways-letNever-constNever-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "always", let: "never", const: "never" }]*/ 4 | function foo1() { 5 | var bar; 6 | var baz; 7 | let qux, 8 | norf; 9 | } 10 | 11 | function foo2() { 12 | const bar = 1, 13 | baz = 2; 14 | let qux, 15 | norf; 16 | } 17 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varConsecutive-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "consecutive" }]*/ 4 | function foo() { 5 | var a, 6 | b; 7 | const c = 1; // `const` and `let` declarations are ignored if they are not specified 8 | const d = 2; 9 | let e; 10 | let f; 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varConsecutive-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "consecutive" }]*/ 4 | function foo() { 5 | var a; 6 | var b; 7 | } 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varNever-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "never" }]*/ 4 | function foo() { 5 | var bar; 6 | var baz; 7 | 8 | // `const` and `let` declarations are ignored if they are not specified 9 | const foobar = 1; 10 | const foobaz = 2; 11 | const barfoo = 1, bazfoo = 2; 12 | let qux; 13 | let norf; 14 | let fooqux, foonorf; 15 | } 16 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varNever-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "never" }]*/ 4 | function foo() { 5 | var bar, 6 | baz; 7 | } 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varNever-letConsecutive-constConsecutive-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "never", let: "consecutive", const: "consecutive" }]*/ 4 | function foo1() { 5 | let a, 6 | b; 7 | 8 | var d; 9 | var e; 10 | 11 | let f; 12 | } 13 | 14 | function foo2() { 15 | const a = 1, 16 | b = 2; 17 | 18 | var c; 19 | var d; 20 | 21 | const e = 3; 22 | } 23 | -------------------------------------------------------------------------------- /tests/javascript/fixes/one-var-varNever-letConsecutive-constConsecutive-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable one-var */ 3 | /*eslint one-var: ["error", { var: "never", let: "consecutive", const: "consecutive" }]*/ 4 | function foo1() { 5 | let a, 6 | b; 7 | let c; 8 | 9 | var d, 10 | e; 11 | } 12 | 13 | function foo2() { 14 | const a = 1, 15 | b = 2; 16 | const c = 3; 17 | 18 | var d, 19 | e; 20 | } 21 | -------------------------------------------------------------------------------- /tests/javascript/fixes/operator-assignment-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable operator-assignment */ 3 | /*eslint operator-assignment: ["error", "always"]*/ 4 | x = y; 5 | x += y; 6 | x = y * z; 7 | x = (x * y) * z; 8 | x[0] /= y; 9 | x[foo()] = x[foo()] % 2; 10 | x = y + x; // `+` is not always commutative (e.g. x = "abc") 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/operator-assignment-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable operator-assignment */ 3 | /*eslint operator-assignment: ["error", "always"]*/ 4 | x = x + y; 5 | x = y * x; 6 | x[0] = x[0] / y; 7 | x.y = x.y << z; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/operator-assignment-never-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable operator-assignment */ 3 | /*eslint operator-assignment: ["error", "never"]*/ 4 | x = x + y; 5 | x.y = x.y / a.b; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/operator-assignment-never-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable operator-assignment */ 3 | /*eslint operator-assignment: ["error", "never"]*/ 4 | x *= y; 5 | x ^= (y + z) / foo(); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-arrow-callback-allowNamedFunctionsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-arrow-callback */ 3 | /* eslint prefer-arrow-callback: [ "error", { "allowNamedFunctions": true } ] */ 4 | foo(function bar() {}); 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-arrow-callback-allowUnboundThisFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-arrow-callback */ 3 | /* eslint prefer-arrow-callback: [ "error", { "allowUnboundThis": false } ] */ 4 | foo(function() { this.a; }); 5 | 6 | foo(function() { (() => this); }); 7 | 8 | someArray.map(function(item) { return this.doSomething(item); }, someObject); 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-arrow-callback-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-arrow-callback */ 3 | /* eslint prefer-arrow-callback: "error" */ 4 | // arrow function callback 5 | foo(a => a); // OK 6 | 7 | // generator as callback 8 | foo(function*() { yield; }); // OK 9 | 10 | // function expression not used as callback or function argument 11 | var foo = function foo(a) { return a; }; // OK 12 | 13 | // unbound function expression callback 14 | foo(function() { return this.a; }); // OK 15 | 16 | // recursive named function callback 17 | foo(function bar(n) { return n && n + bar(n - 1); }); // OK 18 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-arrow-callback-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-arrow-callback */ 3 | /* eslint prefer-arrow-callback: "error" */ 4 | foo(function(a) { return a; }); // ERROR 5 | // prefer: foo(a => a) 6 | 7 | foo(function() { return this.a; }.bind(this)); // ERROR 8 | // prefer: foo(() => this.a) 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: "error"*/ 4 | // using const. 5 | const a = 0; 6 | 7 | // it's never initialized. 8 | let b; 9 | console.log(b); 10 | 11 | // it's reassigned after initialized. 12 | let c; 13 | c = 0; 14 | c = 1; 15 | console.log(c); 16 | 17 | // it's initialized in a different block from the declaration. 18 | let d; 19 | if (true) { 20 | d = 0; 21 | } 22 | console.log(d); 23 | 24 | // it's initialized in a different scope. 25 | let e; 26 | class C { 27 | #x; 28 | static { 29 | e = obj => obj.#x; 30 | } 31 | } 32 | 33 | // it's initialized at a place that we cannot write a variable declaration. 34 | let f; 35 | if (true) f = 0; 36 | console.log(f); 37 | 38 | // `i` gets a new binding each iteration 39 | for (const i in [1, 2, 3]) { 40 | console.log(i); 41 | } 42 | 43 | // `a` gets a new binding each iteration 44 | for (const a of [1, 2, 3]) { 45 | console.log(a); 46 | } 47 | 48 | // `end` is never reassigned, but we cannot separate the declarations without modifying the scope. 49 | for (let i = 0, end = 10; i < end; ++i) { 50 | console.log(i); 51 | } 52 | 53 | // `predicate` is only assigned once but cannot be separately declared as `const` 54 | let predicate; 55 | [object.type, predicate] = foo(); 56 | 57 | // `g` is only assigned once but cannot be separately declared as `const` 58 | let g; 59 | const h = {}; 60 | ({ g, c: h.c } = func()); 61 | 62 | // suggest to use `no-var` rule. 63 | var i = 3; 64 | console.log(i); 65 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-destructuringAll-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: ["error", {"destructuring": "all"}]*/ 4 | // 'b' is never reassigned, but all of `a` and `b` should not be const, so those are ignored. 5 | let {a, b} = obj; 6 | a = a + 1; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-destructuringAll-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: ["error", {"destructuring": "all"}]*/ 4 | // all of `a` and `b` should be const, so those are warned. 5 | let {a, b} = obj; /*error 'a' is never reassigned, use 'const' instead. 6 | 'b' is never reassigned, use 'const' instead.*/ 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-destructuringAny-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: "error"*/ 4 | // using const. 5 | const {a: a0, b} = obj; 6 | const a = a0 + 1; 7 | 8 | // all variables are reassigned. 9 | let {c, d} = obj; 10 | c = c + 1; 11 | d = d + 1; 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-destructuringAny-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: "error"*/ 4 | let {a, b} = obj; /*error 'b' is never reassigned, use 'const' instead.*/ 5 | a = a + 1; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-ignoreReadBeforeAssignFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: ["error", {"ignoreReadBeforeAssign": false}]*/ 4 | const timer = setInterval(initialize, 100); 5 | function initialize() { 6 | if (foo()) { 7 | clearInterval(timer); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-ignoreReadBeforeAssignTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: ["error", {"ignoreReadBeforeAssign": true}]*/ 4 | let timer; 5 | function initialize() { 6 | if (foo()) { 7 | clearInterval(timer); 8 | } 9 | } 10 | timer = setInterval(initialize, 100); 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-const-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-const */ 3 | /*eslint prefer-const: "error"*/ 4 | // it's initialized and never reassigned. 5 | let a = 3; 6 | console.log(a); 7 | 8 | let b; 9 | b = 0; 10 | console.log(b); 11 | 12 | class C { 13 | static { 14 | let a; 15 | a = 0; 16 | console.log(a); 17 | } 18 | } 19 | 20 | // `i` is redefined (not reassigned) on each loop step. 21 | for (let i in [1, 2, 3]) { 22 | console.log(i); 23 | } 24 | 25 | // `a` is redefined (not reassigned) on each loop step. 26 | for (let a of [1, 2, 3]) { 27 | console.log(a); 28 | } 29 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-AssignmentExpressionArrayTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error", {"AssignmentExpression": {"array": true}}] */ 4 | [bar] = array; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-VariableDeclaratorObjectTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error", {"VariableDeclarator": {"object": true}}] */ 4 | var {bar: foo} = object; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error"] */ 4 | // With `array` enabled 5 | var [ foo ] = array; 6 | var foo = array[someIndex]; 7 | 8 | // With `object` enabled 9 | var { foo } = object; 10 | 11 | var foo = object.bar; 12 | 13 | let foo; 14 | ({ foo } = object); 15 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-enforceForRenamedPropertiesTrue-correct-1.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error", {"object": true, "array": true}, {"enforceForRenamedProperties": true}] */ 4 | var { bar: foo } = object; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-enforceForRenamedPropertiesTrue-correct-2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error", {"object": true, "array": true}, {"enforceForRenamedProperties": true}] */ 4 | class C { 5 | #x; 6 | foo() { 7 | const bar = this.#x; // private identifiers are not allowed in destructuring 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-enforceForRenamedPropertiesTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error", {"object": true, "array": true}, {"enforceForRenamedProperties": true}] */ 4 | var foo = object.bar; 5 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-destructuring-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-destructuring */ 3 | /* eslint prefer-destructuring: ["error"] */ 4 | // With `array` enabled 5 | var foo = array[0]; 6 | 7 | // With `object` enabled 8 | var foo = object.foo; 9 | var foo = object['foo']; 10 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-exponentiation-operator-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-exponentiation-operator */ 3 | /*eslint prefer-exponentiation-operator: "error"*/ 4 | const foo = 2 ** 8; 5 | 6 | const bar = a ** b; 7 | 8 | let baz = (a + b) ** (c + d); 9 | 10 | let quux = (-1) ** n; 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-exponentiation-operator-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-exponentiation-operator */ 3 | /*eslint prefer-exponentiation-operator: "error"*/ 4 | const foo = Math.pow(2, 8); 5 | 6 | const bar = Math.pow(a, b); 7 | 8 | let baz = Math.pow(a + b, c + d); 9 | 10 | let quux = Math.pow(-1, n); 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-numeric-literals-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-numeric-literals */ 3 | /*eslint prefer-numeric-literals: "error"*/ 4 | parseInt(1); 5 | parseInt(1, 3); 6 | Number.parseInt(1); 7 | Number.parseInt(1, 3); 8 | 9 | 0b111110111 === 503; 10 | 0o767 === 503; 11 | 0x1F7 === 503; 12 | 13 | a[parseInt](1,2); 14 | 15 | parseInt(foo); 16 | parseInt(foo, 2); 17 | Number.parseInt(foo); 18 | Number.parseInt(foo, 2); 19 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-numeric-literals-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-numeric-literals */ 3 | /*eslint prefer-numeric-literals: "error"*/ 4 | parseInt("111110111", 2) === 503; 5 | parseInt(`111110111`, 2) === 503; 6 | parseInt("767", 8) === 503; 7 | parseInt("1F7", 16) === 503; 8 | Number.parseInt("111110111", 2) === 503; 9 | Number.parseInt("767", 8) === 503; 10 | Number.parseInt("1F7", 16) === 503; 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-object-has-own-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-object-has-own */ 3 | /*eslint prefer-object-has-own: "error"*/ 4 | Object.hasOwn(obj, "a"); 5 | 6 | const hasProperty = Object.hasOwn(object, property); 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-object-has-own-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-object-has-own */ 3 | /*eslint prefer-object-has-own: "error"*/ 4 | Object.prototype.hasOwnProperty.call(obj, "a"); 5 | 6 | Object.hasOwnProperty.call(obj, "a"); 7 | 8 | ({}).hasOwnProperty.call(obj, "a"); 9 | 10 | const hasProperty = Object.prototype.hasOwnProperty.call(object, property); 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-object-spread-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-object-spread */ 3 | /*eslint prefer-object-spread: "error"*/ 4 | Object.assign(...foo); 5 | 6 | // Any Object.assign call without an object literal as the first argument 7 | Object.assign(foo, { bar: baz }); 8 | 9 | Object.assign(foo, Object.assign(bar)); 10 | 11 | Object.assign(foo, { bar, baz }) 12 | 13 | Object.assign(foo, { ...baz }); 14 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-object-spread-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-object-spread */ 3 | /*eslint prefer-object-spread: "error"*/ 4 | Object.assign({}, foo) 5 | 6 | Object.assign({}, {foo: 'bar'}) 7 | 8 | Object.assign({ foo: 'bar'}, baz) 9 | 10 | Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' })) 11 | 12 | Object.assign({}, { foo, bar, baz }) 13 | 14 | Object.assign({}, { ...baz }) 15 | 16 | // Object.assign with a single argument that is an object literal 17 | Object.assign({}); 18 | 19 | Object.assign({ foo: bar }); 20 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-template-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-template */ 3 | /*eslint prefer-template: "error"*/ 4 | var str = "Hello World!"; 5 | var str = `Hello, ${name}!`; 6 | var str = `Time: ${12 * 60 * 60 * 1000}`; 7 | 8 | // This is reported by `no-useless-concat`. 9 | var str = "Hello, " + "World!"; 10 | -------------------------------------------------------------------------------- /tests/javascript/fixes/prefer-template-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-template */ 3 | /*eslint prefer-template: "error"*/ 4 | var str = "Hello, " + name + "!"; 5 | var str = "Time: " + (12 * 60 * 60 * 1000); 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-allowSeparatedGroupsTrue-correct-1.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ 4 | // Correct Code 5 | import b from 'foo.js'; 6 | import c from 'bar.js'; 7 | 8 | import a from 'baz.js'; 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-allowSeparatedGroupsTrue-correct-2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ 4 | // Correct Code 5 | import b from 'foo.js'; 6 | import c from 'bar.js'; 7 | // comment 8 | import a from 'baz.js'; 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-allowSeparatedGroupsTrue-correct-3.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ 4 | // Correct Code 5 | import b from 'foo.js'; 6 | import c from 'bar.js'; 7 | quux(); 8 | import a from 'baz.js'; 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-allowSeparatedGroupsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ 4 | // Incorrect Code 5 | import b from 'foo.js'; 6 | import c from 'bar.js'; 7 | import a from 'baz.js'; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-correct-1.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Correct Code 5 | import a from 'foo.js'; 6 | import b from 'bar.js'; 7 | import c from 'baz.js'; -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-correct-2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Correct Code 5 | import 'module-without-export.js'; 6 | import * as bar from 'bar.js'; 7 | import * as foo from 'foo.js'; 8 | import {alpha, beta} from 'alpha.js'; 9 | import {delta, gamma} from 'delta.js'; 10 | import a from 'baz.js'; 11 | import {b} from 'qux.js'; 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-correct-3.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Correct Code 5 | import 'foo.js' 6 | import * as bar from 'bar.js'; 7 | import {a, b} from 'baz.js'; 8 | import c from 'qux.js'; 9 | import {d} from 'quux.js'; -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-correct-4.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Correct Code 5 | import {a, b, c} from 'foo.js' 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreCaseFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreCase": false }]*/ 4 | // Correct Code 5 | import B from 'bar.js'; 6 | import a from 'foo.js'; 7 | import c from 'baz.js'; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreCaseFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreCase": false }]*/ 4 | // Incorrect Code 5 | import a from 'bar.js'; 6 | import B from 'foo.js'; 7 | import c from 'baz.js'; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreCaseTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreCase": true }]*/ 4 | // Correct Code 5 | import a from 'bar.js'; 6 | import B from 'foo.js'; 7 | import c from 'baz.js'; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreCaseTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreCase": true }]*/ 4 | // Incorrect Code 5 | import B from 'foo.js'; 6 | import a from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreDeclarationSortFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreDeclarationSort": false }]*/ 4 | // Correct Code 5 | import a from 'foo.js' 6 | import b from 'bar.js' 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreDeclarationSortFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreDeclarationSort": false }]*/ 4 | // Incorrect Code 5 | import b from 'foo.js' 6 | import a from 'bar.js' 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreDeclarationSortTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/ 4 | // Correct Code 5 | import b from 'foo.js' 6 | import a from 'bar.js' 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreDeclarationSortTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/ 4 | // Incorrect Code 5 | import {b, a, c} from 'foo.js' 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreMemberSortFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreMemberSort": false }]*/ 4 | // Correct Code 5 | import {a, b, c} from 'foo.js'; 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreMemberSortFalse-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreMemberSort": false }]*/ 4 | // Correct Code 5 | import {b, a, c} from 'foo.js' 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreMemberSortTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreMemberSort": true }]*/ 4 | // Correct Code 5 | import {b, a, c} from 'foo.js' 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-ignoreMemberSortTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "ignoreMemberSort": true }]*/ 4 | // Incorrect Code 5 | import b from 'foo.js'; 6 | import a from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-1.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import a from 'foo.js'; 6 | import A from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-2.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import b from 'foo.js'; 6 | import a from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-3.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import {c, d} from 'foo.js'; 6 | import {a, b} from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-4.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import a from 'foo.js'; 6 | import {b, c} from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-5.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import {a} from 'foo.js'; 6 | import {b, c} from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-6.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import a from 'foo.js'; 6 | import * as b from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-incorrect-7.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: "error"*/ 4 | // Incorrect Code 5 | import {b, a, c} from 'foo.js' 6 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-memberSyntaxSortOrderAllSingleMultipleNone-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "memberSyntaxSortOrder": ['all', 'single', 'multiple', 'none'] }]*/ 4 | // Correct Code 5 | import * as foo from 'foo.js'; 6 | import z from 'zoo.js'; 7 | import {a, b} from 'foo.js'; 8 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-memberSyntaxSortOrderNoneAllMultipleSingle-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "memberSyntaxSortOrder": ["none", "all", "multiple", "single"] }]*/ 4 | // Incorrect Code 5 | import a from 'foo.js'; 6 | import * as b from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-imports-memberSyntaxSortOrderSingleAllMultipleNone-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-imports */ 3 | /*eslint sort-imports: ["error", { "memberSyntaxSortOrder": ['single', 'all', 'multiple', 'none'] }]*/ 4 | // Correct Code 5 | import a from 'foo.js'; 6 | import * as b from 'bar.js'; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-vars-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-vars */ 3 | /*eslint sort-vars: "error"*/ 4 | var a, b, c, d; 5 | 6 | var _a = 10; 7 | var _b = 20; 8 | 9 | var A, a; 10 | 11 | var B, a, c; 12 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-vars-ignoreCaseTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-vars */ 3 | /*eslint sort-vars: ["error", { "ignoreCase": true }]*/ 4 | var a, A; 5 | 6 | var a, B, c; 7 | -------------------------------------------------------------------------------- /tests/javascript/fixes/sort-vars-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable sort-vars */ 3 | /*eslint sort-vars: "error"*/ 4 | var b, a; 5 | 6 | var a, B, c; 7 | 8 | var a, A; 9 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-always-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: ["error", "always"]*/ 4 | if ("blue" == value) { 5 | // ... 6 | } 7 | 8 | if (`blue` == value) { 9 | // ... 10 | } 11 | 12 | if (`blue` == `${value}`) { 13 | // ... 14 | } 15 | 16 | if (-1 < str.indexOf(substr)) { 17 | // ... 18 | } 19 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-always-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: ["error", "always"]*/ 4 | if (color == "blue") { 5 | // ... 6 | } 7 | 8 | if (color == `blue`) { 9 | // ... 10 | } 11 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: "error"*/ 4 | if (5 & value) { 5 | // ... 6 | } 7 | 8 | if (value === "red") { 9 | // ... 10 | } 11 | 12 | if (value === `red`) { 13 | // ... 14 | } 15 | 16 | if (`${value}` === `red`) { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-exceptRangeTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: ["error", "never", { "exceptRange": true }]*/ 4 | function isReddish(color) { 5 | return (color.hue < 60 || 300 < color.hue); 6 | } 7 | 8 | if (x < -1 || 1 < x) { 9 | // ... 10 | } 11 | 12 | if (count < 10 && (0 <= rand && rand < 1)) { 13 | // ... 14 | } 15 | 16 | if (`blue` < x && x < `green`) { 17 | // ... 18 | } 19 | 20 | function howLong(arr) { 21 | return (0 <= arr.length && arr.length < 10) ? "short" : "long"; 22 | } 23 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: "error"*/ 4 | if ("red" === color) { 5 | // ... 6 | } 7 | 8 | if (`red` === color) { 9 | // ... 10 | } 11 | 12 | if (`red` === `${color}`) { 13 | // ... 14 | } 15 | 16 | if (true == flag) { 17 | // ... 18 | } 19 | 20 | if (5 > count) { 21 | // ... 22 | } 23 | 24 | if (-1 < str.indexOf(substr)) { 25 | // ... 26 | } 27 | 28 | if (0 <= x && x < 1) { 29 | // ... 30 | } 31 | -------------------------------------------------------------------------------- /tests/javascript/fixes/yoda-onlyEqualityTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable yoda */ 3 | /*eslint yoda: ["error", "never", { "onlyEquality": true }]*/ 4 | if (x < -1 || 9 < x) { 5 | } 6 | 7 | if (x !== 'foo' && 'bar' != x) { 8 | } 9 | 10 | if (x !== `foo` && `bar` != x) { 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-allowImplicitTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: ["error", { allowImplicit: true }]*/ 4 | var undefAllTheThings = myArray.map(function(item) { 5 | return; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-allowVoidTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: ["error", { allowVoid: true }]*/ 4 | myArray.forEach(item => void handleItem(item)); 5 | 6 | myArray.forEach(item => { 7 | return void handleItem(item); 8 | }); 9 | 10 | myArray.forEach(item => { 11 | if (item < 0) { 12 | return void x; 13 | } 14 | handleItem(item); 15 | }); 16 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-checkForEachTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: ["error", { checkForEach: true }]*/ 4 | myArray.forEach(function(item) { 5 | handleItem(item) 6 | }); 7 | 8 | myArray.forEach(function(item) { 9 | if (item < 0) { 10 | return; 11 | } 12 | handleItem(item); 13 | }); 14 | 15 | myArray.forEach(function(item) { 16 | handleItem(item); 17 | return; 18 | }); 19 | 20 | myArray.forEach(item => { 21 | handleItem(item); 22 | }); 23 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-checkForEachTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: ["error", { checkForEach: true }]*/ 4 | myArray.forEach(function(item) { 5 | return handleItem(item); 6 | }); 7 | 8 | myArray.forEach(function(item) { 9 | if (item < 0) { 10 | return x; 11 | } 12 | handleItem(item); 13 | }); 14 | 15 | myArray.forEach(function(item) { 16 | if (item < 0) { 17 | return void x; 18 | } 19 | handleItem(item); 20 | }); 21 | 22 | myArray.forEach(item => handleItem(item)); 23 | 24 | myArray.forEach(item => void handleItem(item)); 25 | 26 | myArray.forEach(item => { 27 | return handleItem(item); 28 | }); 29 | 30 | myArray.forEach(item => { 31 | return void handleItem(item); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: "error"*/ 4 | var indexMap = myArray.reduce(function(memo, item, index) { 5 | memo[item] = index; 6 | return memo; 7 | }, {}); 8 | 9 | var foo = Array.from(nodes, function(node) { 10 | if (node.tagName === "DIV") { 11 | return true; 12 | } 13 | return false; 14 | }); 15 | 16 | var bar = foo.map(node => node.getAttribute("id")); 17 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/array-callback-return-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable array-callback-return */ 3 | /*eslint array-callback-return: "error"*/ 4 | var indexMap = myArray.reduce(function(memo, item, index) { 5 | memo[item] = index; 6 | }, {}); 7 | 8 | var foo = Array.from(nodes, function(node) { 9 | if (node.tagName === "DIV") { 10 | return true; 11 | } 12 | }); 13 | 14 | var bar = foo.filter(function(x) { 15 | if (x) { 16 | return true; 17 | } else { 18 | return; 19 | } 20 | }); 21 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-array-constructor-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-array-constructor */ 3 | /*eslint no-array-constructor: "error"*/ 4 | Array(500); 5 | 6 | new Array(someOtherArray.length); 7 | 8 | [0, 1, 2]; 9 | 10 | const createArray = Array => new Array(); 11 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-array-constructor-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-array-constructor */ 3 | /*eslint no-array-constructor: "error"*/ 4 | Array(); 5 | 6 | Array(0, 1, 2); 7 | 8 | new Array(0, 1, 2); 9 | 10 | Array(...args); 11 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-case-declarations-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-case-declarations */ 3 | /*eslint no-case-declarations: "error"*/ 4 | // Declarations outside switch-statements are valid 5 | const a = 0; 6 | 7 | switch (foo) { 8 | // The following case clauses are wrapped into blocks using brackets 9 | case 1: { 10 | let x = 1; 11 | break; 12 | } 13 | case 2: { 14 | const y = 2; 15 | break; 16 | } 17 | case 3: { 18 | function f() {} 19 | break; 20 | } 21 | case 4: 22 | // Declarations using var without brackets are valid due to function-scope hoisting 23 | var z = 4; 24 | break; 25 | default: { 26 | class C {} 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-case-declarations-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-case-declarations */ 3 | /*eslint no-case-declarations: "error"*/ 4 | switch (foo) { 5 | case 1: 6 | let x = 1; 7 | break; 8 | case 2: 9 | const y = 2; 10 | break; 11 | case 3: 12 | function f() {} 13 | break; 14 | default: 15 | class C {} 16 | } 17 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-console-allowWarnError-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-console */ 3 | /* eslint no-console: ["error", { allow: ["warn", "error"] }] */ 4 | console.warn("Log a warn level message."); 5 | console.error("Log an error level message."); 6 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-console-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-console */ 3 | /* eslint no-console: "error" */ 4 | // custom console 5 | Console.log("Hello world!"); 6 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-console-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-console */ 3 | /* eslint no-console: "error" */ 4 | console.log("Log a debug level message."); 5 | console.warn("Log a warn level message."); 6 | console.error("Log an error level message."); 7 | console.log = foo(); 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-empty-allowEmptyCatchTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-empty */ 3 | /* eslint no-empty: ["error", { "allowEmptyCatch": true }] */ 4 | try { 5 | doSomething(); 6 | } catch (ex) {} 7 | 8 | try { 9 | doSomething(); 10 | } 11 | catch (ex) {} 12 | finally { 13 | /* continue regardless of error */ 14 | } 15 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-empty-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-empty */ 3 | /*eslint no-empty: "error"*/ 4 | if (foo) { 5 | // empty 6 | } 7 | 8 | while (foo) { 9 | /* empty */ 10 | } 11 | 12 | try { 13 | doSomething(); 14 | } catch (ex) { 15 | // continue regardless of error 16 | } 17 | 18 | try { 19 | doSomething(); 20 | } finally { 21 | /* continue regardless of error */ 22 | } 23 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-empty-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-empty */ 3 | /*eslint no-empty: "error"*/ 4 | if (foo) { 5 | } 6 | 7 | while (foo) { 8 | } 9 | 10 | switch(foo) { 11 | } 12 | 13 | try { 14 | doSomething(); 15 | } catch(ex) { 16 | 17 | } finally { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-allow-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: [2, { "allow": ["!!", "~"] } ]*/ 4 | var b = !!foo; 5 | var b = ~foo.indexOf("."); 6 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-boolean-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var b = Boolean(foo); 5 | var b = foo.indexOf(".") !== -1; 6 | 7 | var n = ~foo; // This is a just bitwise not. 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-boolean-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var b = !!foo; 5 | var b = ~foo.indexOf("."); 6 | // bitwise not is incorrect only with `indexOf`/`lastIndexOf` method calling. 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-disallowTemplateShorthandFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": false }]*/ 4 | var s = `${foo}`; 5 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-disallowTemplateShorthandTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ 4 | var s = String(foo); 5 | 6 | var s = `a${foo}`; 7 | 8 | var s = `${foo}b`; 9 | 10 | var s = `${foo}${bar}`; 11 | 12 | var s = tag`${foo}`; 13 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-disallowTemplateShorthandTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ 4 | var s = `${foo}`; 5 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-number-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var n = Number(foo); 5 | var n = parseFloat(foo); 6 | var n = parseInt(foo, 10); 7 | 8 | var n = foo * 1/4; // `* 1` is allowed when followed by the `/` operator 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-number-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var n = +foo; 5 | var n = -(-foo); 6 | var n = foo - 0; 7 | var n = 1 * foo; 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-string-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var s = String(foo); 5 | foo = String(foo); 6 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-implicit-coercion-string-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-implicit-coercion */ 3 | /*eslint no-implicit-coercion: "error"*/ 4 | var s = "" + foo; 5 | var s = `` + foo; 6 | foo += ""; 7 | foo += ``; 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-misleading-character-class-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-misleading-character-class */ 3 | /*eslint no-misleading-character-class: error */ 4 | /^[abc]$/; 5 | /^[👍]$/u; 6 | /^[\q{👶🏻}]$/v; 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-misleading-character-class-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-misleading-character-class */ 3 | /*eslint no-misleading-character-class: error */ 4 | /^[Á]$/u; 5 | /^[❇️]$/u; 6 | /^[👶🏻]$/u; 7 | /^[🇯🇵]$/u; 8 | /^[👨‍👩‍👦]$/u; 9 | /^[👍]$/; 10 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-nonoctal-decimal-escape-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-nonoctal-decimal-escape */ 3 | /*eslint no-nonoctal-decimal-escape: "error"*/ 4 | "8"; 5 | 6 | "9"; 7 | 8 | var foo = "w8less"; 9 | 10 | var bar = "December 19"; 11 | 12 | var baz = "Don't use \\8 and \\9 escapes."; 13 | 14 | var quux = "\0\u0038"; 15 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-nonoctal-decimal-escape-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-nonoctal-decimal-escape */ 3 | /*eslint no-nonoctal-decimal-escape: "error"*/ 4 | "\8"; 5 | 6 | "\9"; 7 | 8 | var foo = "w\8less"; 9 | 10 | var bar = "December 1\9"; 11 | 12 | var baz = "Don't use \8 and \9 escapes."; 13 | 14 | var quux = "\0\8"; 15 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-object-constructor-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-object-constructor */ 3 | /*eslint no-object-constructor: "error"*/ 4 | Object("foo"); 5 | 6 | const obj = { a: 1, b: 2 }; 7 | 8 | const isObject = value => value === Object(value); 9 | 10 | const createObject = Object => new Object(); 11 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-object-constructor-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-object-constructor */ 3 | /*eslint no-object-constructor: "error"*/ 4 | Object(); 5 | 6 | new Object(); 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-promise-executor-return-allowVoidTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-promise-executor-return */ 3 | /*eslint no-promise-executor-return: ["error", { allowVoid: true }]*/ 4 | new Promise((resolve, reject) => { 5 | if (someCondition) { 6 | return void resolve(defaultResult); 7 | } 8 | getSomething((err, result) => { 9 | if (err) { 10 | reject(err); 11 | } else { 12 | resolve(result); 13 | } 14 | }); 15 | }); 16 | 17 | new Promise((resolve, reject) => void getSomething((err, data) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | resolve(data); 22 | } 23 | })); 24 | 25 | new Promise(r => void r(1)); 26 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-promise-executor-return-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-promise-executor-return */ 3 | /*eslint no-promise-executor-return: "error"*/ 4 | // Turn return inline into two lines 5 | new Promise((resolve, reject) => { 6 | if (someCondition) { 7 | resolve(defaultResult); 8 | return; 9 | } 10 | getSomething((err, result) => { 11 | if (err) { 12 | reject(err); 13 | } else { 14 | resolve(result); 15 | } 16 | }); 17 | }); 18 | 19 | // Add curly braces 20 | new Promise((resolve, reject) => { 21 | getSomething((err, data) => { 22 | if (err) { 23 | reject(err); 24 | } else { 25 | resolve(data); 26 | } 27 | }); 28 | }); 29 | 30 | new Promise(r => { r(1) }); 31 | // or just use Promise.resolve 32 | Promise.resolve(1); 33 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-promise-executor-return-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-promise-executor-return */ 3 | /*eslint no-promise-executor-return: "error"*/ 4 | new Promise((resolve, reject) => { 5 | if (someCondition) { 6 | return defaultResult; 7 | } 8 | getSomething((err, result) => { 9 | if (err) { 10 | reject(err); 11 | } else { 12 | resolve(result); 13 | } 14 | }); 15 | }); 16 | 17 | new Promise((resolve, reject) => getSomething((err, data) => { 18 | if (err) { 19 | reject(err); 20 | } else { 21 | resolve(data); 22 | } 23 | })); 24 | 25 | new Promise(() => { 26 | return 1; 27 | }); 28 | 29 | new Promise(r => r(1)); 30 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-prototype-builtins-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-prototype-builtins */ 3 | /*eslint no-prototype-builtins: "error"*/ 4 | var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar"); 5 | 6 | var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar); 7 | 8 | var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar"); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-prototype-builtins-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-prototype-builtins */ 3 | /*eslint no-prototype-builtins: "error"*/ 4 | var hasBarProperty = foo.hasOwnProperty("bar"); 5 | 6 | var isPrototypeOfBar = foo.isPrototypeOf(bar); 7 | 8 | var barIsEnumerable = foo.propertyIsEnumerable("bar"); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-unsafe-negation-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unsafe-negation */ 3 | /*eslint no-unsafe-negation: "error"*/ 4 | if (!(key in object)) { 5 | // key is not in object 6 | } 7 | 8 | 9 | if (!(obj instanceof Ctor)) { 10 | // obj is not an instance of Ctor 11 | } 12 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-unsafe-negation-enforceForOrderingRelationsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unsafe-negation */ 3 | /*eslint no-unsafe-negation: ["error", { "enforceForOrderingRelations": true }]*/ 4 | if (! a < b) {} 5 | 6 | while (! a > b) {} 7 | 8 | foo = ! a <= b; 9 | 10 | foo = ! a >= b; 11 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-unsafe-negation-exception-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unsafe-negation */ 3 | /*eslint no-unsafe-negation: "error"*/ 4 | if ((!foo) in object) { 5 | // allowed, because the negation is explicitly wrapped in parentheses 6 | // it is equivalent to (foo ? "false" : "true") in object 7 | // this is allowed as an exception for rare situations when that is the intended meaning 8 | } 9 | 10 | if(("" + !foo) in object) { 11 | // you can also make the intention more explicit, with type conversion 12 | } 13 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-unsafe-negation-exception-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unsafe-negation */ 3 | /*eslint no-unsafe-negation: "error"*/ 4 | if (!(foo) in object) { 5 | // this is not an allowed exception 6 | } 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-unsafe-negation-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-unsafe-negation */ 3 | /*eslint no-unsafe-negation: "error"*/ 4 | if (!key in object) { 5 | // operator precedence makes it equivalent to (!key) in object 6 | // and type conversion makes it equivalent to (key ? "false" : "true") in object 7 | } 8 | 9 | 10 | if (!obj instanceof Ctor) { 11 | // operator precedence makes it equivalent to (!obj) instanceof Ctor 12 | // and it equivalent to always false since boolean values are not objects. 13 | } 14 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-useless-escape-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-escape */ 3 | /*eslint no-useless-escape: "error"*/ 4 | "\""; 5 | '\''; 6 | "\x12"; 7 | "\u00a9"; 8 | "\371"; 9 | "xs\u2111"; 10 | `\``; 11 | `\${${foo}}`; 12 | `$\{${foo}}`; 13 | /\\/g; 14 | /\t/g; 15 | /\w\$\*\^\./; 16 | /[[]/; 17 | /[\]]/; 18 | /[a-z-]/; 19 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/no-useless-escape-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable no-useless-escape */ 3 | /*eslint no-useless-escape: "error"*/ 4 | "\'"; 5 | '\"'; 6 | "\#"; 7 | "\e"; 8 | `\"`; 9 | `\"${foo}\"`; 10 | `\#{foo}`; 11 | /\!/; 12 | /\@/; 13 | /[\[]/; 14 | /[a-z\-]/; 15 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-named-capture-group-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-named-capture-group */ 3 | /*eslint prefer-named-capture-group: "error"*/ 4 | const foo = /(?ba[rz])/; 5 | const bar = new RegExp('(?ba[rz])'); 6 | const baz = RegExp('(?ba[rz])'); 7 | const xyz = /xyz(?:zy|abc)/; 8 | 9 | foo.exec('bar').groups.id; // Retrieve the group result. 10 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-named-capture-group-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-named-capture-group */ 3 | /*eslint prefer-named-capture-group: "error"*/ 4 | const foo = /(ba[rz])/; 5 | const bar = new RegExp('(ba[rz])'); 6 | const baz = RegExp('(ba[rz])'); 7 | 8 | foo.exec('bar')[1]; // Retrieve the group result. 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-regex-literals-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-regex-literals */ 3 | /*eslint prefer-regex-literals: "error"*/ 4 | /abc/; 5 | 6 | /abc/u; 7 | 8 | /\d\d\.\d\d\.\d\d\d\d/; 9 | 10 | /^\d\.$/; 11 | 12 | // RegExp constructor is allowed for dynamically generated regular expressions 13 | 14 | new RegExp(pattern); 15 | 16 | RegExp("abc", flags); 17 | 18 | new RegExp(prefix + "abc"); 19 | 20 | RegExp(`${prefix}abc`); 21 | 22 | new RegExp(String.raw`^\d\. ${suffix}`); 23 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-regex-literals-disallowRedundantWrappingTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-regex-literals */ 3 | /*eslint prefer-regex-literals: ["error", {"disallowRedundantWrapping": true}]*/ 4 | /abc/; 5 | 6 | /abc/u; 7 | 8 | new RegExp(/abc/, flags); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-regex-literals-disallowRedundantWrappingTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-regex-literals */ 3 | /*eslint prefer-regex-literals: ["error", {"disallowRedundantWrapping": true}]*/ 4 | new RegExp(/abc/); 5 | 6 | new RegExp(/abc/, 'u'); 7 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/prefer-regex-literals-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable prefer-regex-literals */ 3 | /*eslint prefer-regex-literals: "error"*/ 4 | new RegExp("abc"); 5 | 6 | new RegExp("abc", "u"); 7 | 8 | RegExp("abc"); 9 | 10 | RegExp("abc", "u"); 11 | 12 | new RegExp("\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d"); 13 | 14 | RegExp(`^\\d\\.$`); 15 | 16 | new RegExp(String.raw`^\d\.$`); 17 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/radix-asNeeded-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable radix */ 3 | /*eslint radix: ["error", "as-needed"]*/ 4 | var num = parseInt("071"); 5 | 6 | var num = parseInt("071", 8); 7 | 8 | var num = parseFloat(someValue); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/radix-asNeeded-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable radix */ 3 | /*eslint radix: ["error", "as-needed"]*/ 4 | var num = parseInt("071", 10); 5 | 6 | var num = parseInt("071", "abc"); 7 | 8 | var num = parseInt(); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/radix-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable radix */ 3 | /*eslint radix: "error"*/ 4 | var num = parseInt("071", 10); 5 | 6 | var num = parseInt("071", 8); 7 | 8 | var num = parseFloat(someValue); 9 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/radix-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable radix */ 3 | /*eslint radix: "error"*/ 4 | var num = parseInt("071"); 5 | 6 | var num = parseInt(someValue); 7 | 8 | var num = parseInt("071", "abc"); 9 | 10 | var num = parseInt("071", 37); 11 | 12 | var num = parseInt(); 13 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/require-unicode-regexp-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable require-unicode-regexp */ 3 | /*eslint require-unicode-regexp: "error"*/ 4 | const a = /aaa/u 5 | const b = /bbb/giu 6 | const c = new RegExp("ccc", "u") 7 | const d = new RegExp("ddd", "giu") 8 | 9 | const e = /aaa/v 10 | const f = /bbb/giv 11 | const g = new RegExp("ccc", "v") 12 | const h = new RegExp("ddd", "giv") 13 | 14 | // This rule ignores RegExp calls if the flags could not be evaluated to a static value. 15 | function i(flags) { 16 | return new RegExp("eee", flags) 17 | } 18 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/require-unicode-regexp-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable require-unicode-regexp */ 3 | /*eslint require-unicode-regexp: "error"*/ 4 | const a = /aaa/ 5 | const b = /bbb/gi 6 | const c = new RegExp("ccc") 7 | const d = new RegExp("ddd", "gi") 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: "error"*/ 4 | if (isNaN(foo)) { 5 | // ... 6 | } 7 | 8 | if (!isNaN(foo)) { 9 | // ... 10 | } 11 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-enforceForIndexOfTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: ["error", {"enforceForIndexOf": true}]*/ 4 | function myIsNaN(val) { 5 | return typeof val === "number" && isNaN(val); 6 | } 7 | 8 | function indexOfNaN(arr) { 9 | for (var i = 0; i < arr.length; i++) { 10 | if (myIsNaN(arr[i])) { 11 | return i; 12 | } 13 | } 14 | return -1; 15 | } 16 | 17 | function lastIndexOfNaN(arr) { 18 | for (var i = arr.length - 1; i >= 0; i--) { 19 | if (myIsNaN(arr[i])) { 20 | return i; 21 | } 22 | } 23 | return -1; 24 | } 25 | 26 | var hasNaN = myArray.some(myIsNaN); 27 | 28 | var hasNaN = indexOfNaN(myArray) >= 0; 29 | 30 | var firstIndex = indexOfNaN(myArray); 31 | 32 | var lastIndex = lastIndexOfNaN(myArray); 33 | 34 | // ES2015 35 | var hasNaN = myArray.some(Number.isNaN); 36 | 37 | // ES2015 38 | var firstIndex = myArray.findIndex(Number.isNaN); 39 | 40 | // ES2016 41 | var hasNaN = myArray.includes(NaN); 42 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-enforceForIndexOfTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: ["error", {"enforceForIndexOf": true}]*/ 4 | var hasNaN = myArray.indexOf(NaN) >= 0; 5 | 6 | var firstIndex = myArray.indexOf(NaN); 7 | 8 | var lastIndex = myArray.lastIndexOf(NaN); 9 | 10 | var indexWithSequenceExpression = myArray.indexOf((doStuff(), NaN)); 11 | 12 | var firstIndexFromSecondElement = myArray.indexOf(NaN, 1); 13 | 14 | var lastIndexFromSecondElement = myArray.lastIndexOf(NaN, 1); 15 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-enforceForSwitchCaseFalse-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: ["error", {"enforceForSwitchCase": false}]*/ 4 | switch (foo) { 5 | case NaN: 6 | bar(); 7 | break; 8 | case 1: 9 | baz(); 10 | break; 11 | // ... 12 | } 13 | 14 | switch (NaN) { 15 | case a: 16 | bar(); 17 | break; 18 | case b: 19 | baz(); 20 | break; 21 | // ... 22 | } 23 | 24 | switch (foo) { 25 | case Number.NaN: 26 | bar(); 27 | break; 28 | case 1: 29 | baz(); 30 | break; 31 | // ... 32 | } 33 | 34 | switch (Number.NaN) { 35 | case a: 36 | bar(); 37 | break; 38 | case b: 39 | baz(); 40 | break; 41 | // ... 42 | } 43 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-enforceForSwitchCaseTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: ["error", {"enforceForSwitchCase": true}]*/ 4 | if (Number.isNaN(foo)) { 5 | bar(); 6 | } else { 7 | switch (foo) { 8 | case 1: 9 | baz(); 10 | break; 11 | // ... 12 | } 13 | } 14 | 15 | if (Number.isNaN(a)) { 16 | bar(); 17 | } else if (Number.isNaN(b)) { 18 | baz(); 19 | } // ... 20 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-enforceForSwitchCaseTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: ["error", {"enforceForSwitchCase": true}]*/ 4 | switch (foo) { 5 | case NaN: 6 | bar(); 7 | break; 8 | case 1: 9 | baz(); 10 | break; 11 | // ... 12 | } 13 | 14 | switch (NaN) { 15 | case a: 16 | bar(); 17 | break; 18 | case b: 19 | baz(); 20 | break; 21 | // ... 22 | } 23 | 24 | switch (foo) { 25 | case Number.NaN: 26 | bar(); 27 | break; 28 | case 1: 29 | baz(); 30 | break; 31 | // ... 32 | } 33 | 34 | switch (Number.NaN) { 35 | case a: 36 | bar(); 37 | break; 38 | case b: 39 | baz(); 40 | break; 41 | // ... 42 | } 43 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/use-isnan-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable use-isnan */ 3 | /*eslint use-isnan: "error"*/ 4 | if (foo == NaN) { 5 | // ... 6 | } 7 | 8 | if (foo != NaN) { 9 | // ... 10 | } 11 | 12 | if (foo == Number.NaN) { 13 | // ... 14 | } 15 | 16 | if (foo != Number.NaN) { 17 | // ... 18 | } 19 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/valid-typeof-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable valid-typeof */ 3 | /*eslint valid-typeof: "error"*/ 4 | typeof foo === "string" 5 | typeof bar == "undefined" 6 | typeof foo === baz 7 | typeof bar === typeof qux 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/valid-typeof-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable valid-typeof */ 3 | /*eslint valid-typeof: "error"*/ 4 | typeof foo === "strnig" 5 | typeof foo == "undefimed" 6 | typeof bar != "nunber" 7 | typeof bar !== "fucntion" 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/valid-typeof-requireStringLiteralsTrue-correct.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable valid-typeof */ 3 | /*eslint valid-typeof: ["error", { "requireStringLiterals": true }]*/ 4 | typeof foo === "undefined" 5 | typeof bar == "object" 6 | typeof baz === "string" 7 | typeof bar === typeof qux 8 | -------------------------------------------------------------------------------- /tests/javascript/suggestions/valid-typeof-requireStringLiteralsTrue-incorrect.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* eslint-enable valid-typeof */ 3 | /*eslint valid-typeof: ["error", { "requireStringLiterals": true }]*/ 4 | typeof foo === undefined 5 | typeof bar == Object 6 | typeof baz === "strnig" 7 | typeof qux === "some invalid type" 8 | typeof baz === anotherVariable 9 | typeof foo == 5 10 | --------------------------------------------------------------------------------