diff --git a/.all-contributorsrc b/.all-contributorsrc deleted file mode 100644 index 83cf734ca4ed..000000000000 --- a/.all-contributorsrc +++ /dev/null @@ -1,413 +0,0 @@ -{ - "projectName": "typescript-eslint", - "projectOwner": "typescript-eslint", - "repoType": "github", - "repoHost": "https://github.com", - "files": [ - "CONTRIBUTORS.md" - ], - "imageSize": 100, - "commit": false, - "contributors": [ - { - "login": "bradzacher", - "name": "Brad Zacher", - "avatar_url": "https://avatars.githubusercontent.com/u/7462525?v=4", - "profile": "https://github.com/bradzacher", - "contributions": [] - }, - { - "login": "JamesHenry", - "name": "James Henry", - "avatar_url": "https://avatars.githubusercontent.com/u/900523?v=4", - "profile": "https://github.com/JamesHenry", - "contributions": [] - }, - { - "login": "armano2", - "name": "Armano", - "avatar_url": "https://avatars.githubusercontent.com/u/625469?v=4", - "profile": "https://github.com/armano2", - "contributions": [] - }, - { - "login": "a-tarasyuk", - "name": "Oleksandr T.", - "avatar_url": "https://avatars.githubusercontent.com/u/509265?v=4", - "profile": "https://github.com/a-tarasyuk", - "contributions": [] - }, - { - "login": "soda0289", - "name": "Reyad Attiyat", - "avatar_url": "https://avatars.githubusercontent.com/u/2373964?v=4", - "profile": "https://github.com/soda0289", - "contributions": [] - }, - { - "login": "weirdpattern", - "name": "Patricio Trevino", - "avatar_url": "https://avatars.githubusercontent.com/u/19519411?v=4", - "profile": "https://github.com/weirdpattern", - "contributions": [] - }, - { - "login": "G-Rath", - "name": "Gareth Jones", - "avatar_url": "https://avatars.githubusercontent.com/u/3151613?v=4", - "profile": "https://github.com/G-Rath", - "contributions": [] - }, - { - "login": "JoshuaKGoldberg", - "name": "Josh Goldberg", - "avatar_url": "https://avatars.githubusercontent.com/u/3335181?v=4", - "profile": "https://github.com/JoshuaKGoldberg", - "contributions": [] - }, - { - "login": "nzakas", - "name": "Nicholas C. Zakas", - "avatar_url": "https://avatars.githubusercontent.com/u/38546?v=4", - "profile": "https://github.com/nzakas", - "contributions": [] - }, - { - "login": "j-f1", - "name": "Jed Fox", - "avatar_url": "https://avatars.githubusercontent.com/u/25517624?v=4", - "profile": "https://github.com/j-f1", - "contributions": [] - }, - { - "login": "yeonjuan", - "name": "YeonJuan", - "avatar_url": "https://avatars.githubusercontent.com/u/41323220?v=4", - "profile": "https://github.com/yeonjuan", - "contributions": [] - }, - { - "login": "uniqueiniquity", - "name": "Ben Lichtman", - "avatar_url": "https://avatars.githubusercontent.com/u/9092011?v=4", - "profile": "https://github.com/uniqueiniquity", - "contributions": [] - }, - { - "login": "phaux", - "name": "Nikita Stefaniak", - "avatar_url": "https://avatars.githubusercontent.com/u/1270987?v=4", - "profile": "https://github.com/phaux", - "contributions": [] - }, - { - "login": "scottohara", - "name": "Scott O'Hara", - "avatar_url": "https://avatars.githubusercontent.com/u/289327?v=4", - "profile": "https://github.com/scottohara", - "contributions": [] - }, - { - "login": "Retsam", - "name": "Retsam", - "avatar_url": "https://avatars.githubusercontent.com/u/2281166?v=4", - "profile": "https://github.com/Retsam", - "contributions": [] - }, - { - "login": "sosukesuzuki", - "name": "Sosuke Suzuki", - "avatar_url": "https://avatars.githubusercontent.com/u/14838850?v=4", - "profile": "https://github.com/sosukesuzuki", - "contributions": [] - }, - { - "login": "kaicataldo", - "name": "Kai Cataldo", - "avatar_url": "https://avatars.githubusercontent.com/u/7041728?v=4", - "profile": "https://github.com/kaicataldo", - "contributions": [] - }, - { - "login": "Pajn", - "name": "Rasmus Eneman", - "avatar_url": "https://avatars.githubusercontent.com/u/817422?v=4", - "profile": "https://github.com/Pajn", - "contributions": [] - }, - { - "login": "mysticatea", - "name": "Toru Nagashima", - "avatar_url": "https://avatars.githubusercontent.com/u/1937871?v=4", - "profile": "https://github.com/mysticatea", - "contributions": [] - }, - { - "login": "azz", - "name": "Lucas Azzola", - "avatar_url": "https://avatars.githubusercontent.com/u/1297597?v=4", - "profile": "https://github.com/azz", - "contributions": [] - }, - { - "login": "dannyfritz", - "name": "Danny Fritz", - "avatar_url": "https://avatars.githubusercontent.com/u/315788?v=4", - "profile": "https://github.com/dannyfritz", - "contributions": [] - }, - { - "login": "ikatyang", - "name": "Ika", - "avatar_url": "https://avatars.githubusercontent.com/u/8341033?v=4", - "profile": "https://github.com/ikatyang", - "contributions": [] - }, - { - "login": "macklinu", - "name": "mackie", - "avatar_url": "https://avatars.githubusercontent.com/u/2344137?v=4", - "profile": "https://github.com/macklinu", - "contributions": [] - }, - { - "login": "JounQin", - "name": "JounQin", - "avatar_url": "https://avatars.githubusercontent.com/u/8336744?v=4", - "profile": "https://github.com/JounQin", - "contributions": [] - }, - { - "login": "lukyth", - "name": "Kanitkorn Sujautra", - "avatar_url": "https://avatars.githubusercontent.com/u/7040242?v=4", - "profile": "https://github.com/lukyth", - "contributions": [] - }, - { - "login": "cherryblossom000", - "name": "cherryblossom000", - "avatar_url": "https://avatars.githubusercontent.com/u/31467609?v=4", - "profile": "https://github.com/cherryblossom000", - "contributions": [] - }, - { - "login": "SimenB", - "name": "Simen Bekkhus", - "avatar_url": "https://avatars.githubusercontent.com/u/1404810?v=4", - "profile": "https://github.com/SimenB", - "contributions": [] - }, - { - "login": "anikethsaha", - "name": "Anix", - "avatar_url": "https://avatars.githubusercontent.com/u/26347874?v=4", - "profile": "https://github.com/anikethsaha", - "contributions": [] - }, - { - "login": "octogonz", - "name": "Pete Gonzalez", - "avatar_url": "https://avatars.githubusercontent.com/u/4673363?v=4", - "profile": "https://github.com/octogonz", - "contributions": [] - }, - { - "login": "ldrick", - "name": "ldrick", - "avatar_url": "https://avatars.githubusercontent.com/u/3674067?v=4", - "profile": "https://github.com/ldrick", - "contributions": [] - }, - { - "login": "susisu", - "name": "Susisu", - "avatar_url": "https://avatars.githubusercontent.com/u/2443491?v=4", - "profile": "https://github.com/susisu", - "contributions": [] - }, - { - "login": "vapurrmaid", - "name": "G r e y", - "avatar_url": "https://avatars.githubusercontent.com/u/11184711?v=4", - "profile": "https://github.com/vapurrmaid", - "contributions": [] - }, - { - "login": "gavinbarron", - "name": "Gavin Barron", - "avatar_url": "https://avatars.githubusercontent.com/u/7122716?v=4", - "profile": "https://github.com/gavinbarron", - "contributions": [] - }, - { - "login": "platinumazure", - "name": "Kevin Partington", - "avatar_url": "https://avatars.githubusercontent.com/u/284282?v=4", - "profile": "https://github.com/platinumazure", - "contributions": [] - }, - { - "login": "duailibe", - "name": "Lucas Duailibe", - "avatar_url": "https://avatars.githubusercontent.com/u/1574588?v=4", - "profile": "https://github.com/duailibe", - "contributions": [] - }, - { - "login": "Validark", - "name": "Validark", - "avatar_url": "https://avatars.githubusercontent.com/u/15217173?v=4", - "profile": "https://github.com/Validark", - "contributions": [] - }, - { - "login": "pablobirukov", - "name": "Pavel Birukov ", - "avatar_url": "https://avatars.githubusercontent.com/u/1861546?v=4", - "profile": "https://github.com/pablobirukov", - "contributions": [] - }, - { - "login": "mightyiam", - "name": "Shahar Dawn Or", - "avatar_url": "https://avatars.githubusercontent.com/u/635591?v=4", - "profile": "https://github.com/mightyiam", - "contributions": [] - }, - { - "login": "ulrichb", - "name": "ulrichb", - "avatar_url": "https://avatars.githubusercontent.com/u/388796?v=4", - "profile": "https://github.com/ulrichb", - "contributions": [] - }, - { - "login": "ddubrava", - "name": "Daniil Dubrava", - "avatar_url": "https://avatars.githubusercontent.com/u/22116465?v=4", - "profile": "https://github.com/ddubrava", - "contributions": [] - }, - { - "login": "danielnixon", - "name": "Daniel Nixon", - "avatar_url": "https://avatars.githubusercontent.com/u/6418489?v=4", - "profile": "https://github.com/danielnixon", - "contributions": [] - }, - { - "login": "webschik", - "name": "Denys Kniazevych", - "avatar_url": "https://avatars.githubusercontent.com/u/1665314?v=4", - "profile": "https://github.com/webschik", - "contributions": [] - }, - { - "login": "dimitropoulos", - "name": "Dimitri Mitropoulos", - "avatar_url": "https://avatars.githubusercontent.com/u/15232461?v=4", - "profile": "https://github.com/dimitropoulos", - "contributions": [] - }, - { - "login": "nevir", - "name": "Ian MacLeod", - "avatar_url": "https://avatars.githubusercontent.com/u/41373?v=4", - "profile": "https://github.com/nevir", - "contributions": [] - }, - { - "login": "jonathanrdelgado", - "name": "Jonathan Delgado", - "avatar_url": "https://avatars.githubusercontent.com/u/1841149?v=4", - "profile": "https://github.com/jonathanrdelgado", - "contributions": [] - }, - { - "login": "flying-sheep", - "name": "Philipp A.", - "avatar_url": "https://avatars.githubusercontent.com/u/291575?v=4", - "profile": "https://github.com/flying-sheep", - "contributions": [] - }, - { - "login": "g-plane", - "name": "Pig Fang", - "avatar_url": "https://avatars.githubusercontent.com/u/17216317?v=4", - "profile": "https://github.com/g-plane", - "contributions": [] - }, - { - "login": "tadhgmister", - "name": "Tadhg McDonald-Jensen", - "avatar_url": "https://avatars.githubusercontent.com/u/18615763?v=4", - "profile": "https://github.com/tadhgmister", - "contributions": [] - }, - { - "login": "ThomasdenH", - "name": "Thomas den Hollander", - "avatar_url": "https://avatars.githubusercontent.com/u/3889750?v=4", - "profile": "https://github.com/ThomasdenH", - "contributions": [] - }, - { - "login": "timkraut", - "name": "Tim Kraut", - "avatar_url": "https://avatars.githubusercontent.com/u/509669?v=4", - "profile": "https://github.com/timkraut", - "contributions": [] - }, - { - "login": "magurotuna", - "name": "Yusuke Tanaka", - "avatar_url": "https://avatars.githubusercontent.com/u/23649474?v=4", - "profile": "https://github.com/magurotuna", - "contributions": [] - }, - { - "login": "Zzzen", - "name": "Zzzen", - "avatar_url": "https://avatars.githubusercontent.com/u/6630042?v=4", - "profile": "https://github.com/Zzzen", - "contributions": [] - }, - { - "login": "koooge", - "name": "koooge", - "avatar_url": "https://avatars.githubusercontent.com/u/7419215?v=4", - "profile": "https://github.com/koooge", - "contributions": [] - }, - { - "login": "thomasmichaelwallace", - "name": "thomas michael wallace", - "avatar_url": "https://avatars.githubusercontent.com/u/1954845?v=4", - "profile": "https://github.com/thomasmichaelwallace", - "contributions": [] - }, - { - "login": "madbence", - "name": "Bence Dányi", - "avatar_url": "https://avatars.githubusercontent.com/u/296735?v=4", - "profile": "https://github.com/madbence", - "contributions": [] - }, - { - "login": "soobing", - "name": "Soobin Bak", - "avatar_url": "https://avatars.githubusercontent.com/u/16860535?v=4", - "profile": "https://github.com/soobing", - "contributions": [] - }, - { - "login": "RebeccaStevens", - "name": "Rebecca Stevens", - "avatar_url": "https://avatars.githubusercontent.com/u/7224206?v=4", - "profile": "https://github.com/RebeccaStevens", - "contributions": [] - } - ], - "contributorsPerLine": 5 -} \ No newline at end of file diff --git a/.cspell.json b/.cspell.json index 4a8c0ad226be..09466a9d300a 100644 --- a/.cspell.json +++ b/.cspell.json @@ -114,7 +114,7 @@ ], "overrides": [ { - "filename": "**/*.{ts,js,tsx,jsx}", + "filename": "**/*.{ts,mts,cts,js,cjs,mjs,tsx,jsx}", "ignoreRegExpList": ["/@[a-z]+/", "/#(end)?region/"], "includeRegExpList": [ "/\\/\\*[\\s\\S]*?\\*\\/|([^\\\\:]|^)\\/\\/.*$/", diff --git a/.github/ISSUE_TEMPLATE/6-bug-report-other.yaml b/.github/ISSUE_TEMPLATE/6-bug-report-other.yaml index ea53641e6dc3..5f3e16c61517 100644 --- a/.github/ISSUE_TEMPLATE/6-bug-report-other.yaml +++ b/.github/ISSUE_TEMPLATE/6-bug-report-other.yaml @@ -38,6 +38,7 @@ body: - scope-manager - typescript-estree - utils + - website validations: required: true - type: input diff --git a/.github/ISSUE_TEMPLATE/7-enhancement-other.yaml b/.github/ISSUE_TEMPLATE/7-enhancement-other.yaml index 6a15011be4d0..d68dea5a65ea 100644 --- a/.github/ISSUE_TEMPLATE/7-enhancement-other.yaml +++ b/.github/ISSUE_TEMPLATE/7-enhancement-other.yaml @@ -29,6 +29,7 @@ body: - scope-manager - typescript-estree - utils + - website validations: required: true - type: checkboxes diff --git a/.github/ISSUE_TEMPLATE/9-repo-maintenance.yaml b/.github/ISSUE_TEMPLATE/9-repo-maintenance.yaml new file mode 100644 index 000000000000..1f35a7cd59bd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/9-repo-maintenance.yaml @@ -0,0 +1,18 @@ +name: "🏗 Suggest an Improvement with Repository Maintenance" +description: Report a bug or request a feature related to developing the typescript-eslint monorepo +title: "Repo: " +labels: + - "repo maintenance" + - triage +body: + - type: markdown + attributes: + value: | + This issue form is specifically for work done in this repository. Only use it if you are suggesting a change to repository tooling. Don't use it for work in any other repository. + - type: textarea + attributes: + label: Suggestion + description: Tell us exactly what you'd like to see happen. Please be as specific as possible here. + placeholder: I want a new CI action that does X when Y ... + validations: + required: true diff --git a/.github/actions/prepare-install/action.yml b/.github/actions/prepare-install/action.yml index 73fc2191a0dc..4d28fccf7b26 100644 --- a/.github/actions/prepare-install/action.yml +++ b/.github/actions/prepare-install/action.yml @@ -31,7 +31,9 @@ runs: - uses: actions/cache@v3 id: yarn-cache with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + path: | + ${{ steps.yarn-cache-dir-path.outputs.dir }} + ~/.cache/Cypress key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2e01de99389..533fd57ce0a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -193,6 +193,9 @@ jobs: - name: Build uses: ./.github/actions/prepare-build + - name: Install Cypress + run: yarn cypress install + - name: Cypress run uses: cypress-io/github-action@v2 with: diff --git a/.github/workflows/generate-contributors.yml b/.github/workflows/generate-contributors.yml index 1e141d67ce91..f04ff684ecc2 100644 --- a/.github/workflows/generate-contributors.yml +++ b/.github/workflows/generate-contributors.yml @@ -5,7 +5,7 @@ on: - cron: "0 0 1 * *" env: - PRIMARY_NODE_VERSION: 12 + PRIMARY_NODE_VERSION: 16 jobs: generate-contributors: @@ -13,22 +13,30 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Get typescript-eslint Github app token + id: get_token + uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 + with: + private_key: ${{ secrets.GH_APP_PEM }} + app_id: ${{ secrets.GH_APP_ID }} + - name: Use Node.js ${{ env.PRIMARY_NODE_VERSION }} uses: actions/setup-node@v3 with: node-version: ${{ env.PRIMARY_NODE_VERSION }} - - name: Get yarn cache directory path + - name: Get yarn cache directory path and node version for cache key id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" + run: | + echo "::set-output name=dir::$(yarn cache dir)" + echo "::set-output name=node_version::$(node --version)" - uses: actions/cache@v3 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | - ${{ runner.os }}-yarn- + ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn- - name: Install dependencies run: | @@ -40,11 +48,10 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: - # The standard GITHUB_TOKEN cannot be used as it will not trigger status checks on - # the PR that gets created (this behavior is not specific to this action). - # https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs - token: ${{ secrets.JAMES_HENRY_GH_TOKEN }} + token: ${{ steps.get_token.outputs.token }} commit-message: "chore: update contributors" title: "chore: update contributors" body: "" branch: auto-update-contributors + committer: typescript-eslint[bot] + author: typescript-eslint[bot] diff --git a/.github/workflows/update-sponsors.yml b/.github/workflows/update-sponsors.yml index 29a3bb1d08d1..148335ced8c5 100644 --- a/.github/workflows/update-sponsors.yml +++ b/.github/workflows/update-sponsors.yml @@ -4,23 +4,55 @@ on: schedule: - cron: "0 0 * * 1" +env: + PRIMARY_NODE_VERSION: 16 + jobs: build: name: Commit if needed runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: Codecademy/run-on-yarn@v1 + + - name: Use Node.js ${{ env.PRIMARY_NODE_VERSION }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.PRIMARY_NODE_VERSION }} + + - name: Get yarn cache directory path and node version for cache key + id: yarn-cache-dir-path + run: | + echo "::set-output name=dir::$(yarn cache dir)" + echo "::set-output name=node_version::$(node --version)" + + - uses: actions/cache@v3 with: - command: generate-sponsors + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node-${{ steps.yarn-cache-dir-path.outputs.node_version }}-yarn- + + - name: Install dependencies + run: | + yarn --ignore-engines --frozen-lockfile --ignore-scripts + + - name: Get typescript-eslint Github app token + id: get_token + uses: getsentry/action-github-app-token@38a3ce582e170ddfe8789f509597c6944f2292a9 + with: + private_key: ${{ secrets.GH_APP_PEM }} + app_id: ${{ secrets.GH_APP_ID }} + + - name: Generate sponsors + run: yarn generate-sponsors + - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: - # The standard GITHUB_TOKEN cannot be used as it will not trigger status checks on - # the PR that gets created (this behavior is not specific to this action). - # https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#triggering-further-workflow-runs - token: ${{ secrets.JAMES_HENRY_GH_TOKEN }} + token: ${{ steps.get_token.outputs.token }} commit-message: "chore: update sponsors" title: "chore: update sponsors" body: "💸" branch: auto-update-sponsors + committer: typescript-eslint[bot] + author: typescript-eslint[bot] diff --git a/.lintstagedrc b/.lintstagedrc index e4d508f67844..691f6e0eb0e5 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,5 +1,5 @@ { - "*.{ts,js,json,md}": [ + "*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}": [ "prettier --write" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6552077df3d7..ca7f055a3475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,28 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Bug Fixes + +* **eslint-plugin:** [no-type-alias] handle Template Literal Types ([#5092](https://github.com/typescript-eslint/typescript-eslint/issues/5092)) ([8febf11](https://github.com/typescript-eslint/typescript-eslint/commit/8febf11a9296d1c0d7ccdf91ef9ab92ec8dfc39c)) +* **types:** remove leftovers from removal of useJSXTextNode ([#5091](https://github.com/typescript-eslint/typescript-eslint/issues/5091)) ([f9c3647](https://github.com/typescript-eslint/typescript-eslint/commit/f9c3647cb637c8d1ee461b471da9d817ccbde77c)) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) +* [TS4.7] support type parameters for `typeof` ([#5067](https://github.com/typescript-eslint/typescript-eslint/issues/5067)) ([836de79](https://github.com/typescript-eslint/typescript-eslint/commit/836de79e8d1bff43149168cc913a4c2b60e79bf6)) +* bump dependency ranges to TypeScript 4.7 ([#5082](https://github.com/typescript-eslint/typescript-eslint/issues/5082)) ([c4310b1](https://github.com/typescript-eslint/typescript-eslint/commit/c4310b1aac35c7d31b826f0602eca6a5900a09ee)) +* **eslint-plugin:** [ban-ts-comment] add descriptionFormat option ([#5026](https://github.com/typescript-eslint/typescript-eslint/issues/5026)) ([1fb31a4](https://github.com/typescript-eslint/typescript-eslint/commit/1fb31a4b3e05734f801ade0450fea33494e4d5e6)) +* **eslint-plugin:** [no-misused-promises] warn when spreading promises ([#5053](https://github.com/typescript-eslint/typescript-eslint/issues/5053)) ([61ffa9e](https://github.com/typescript-eslint/typescript-eslint/commit/61ffa9ed70e3cac6eca50a6c3cc5a0f1e7dec11c)) +* **eslint-plugin:** [space-infix-ops] missing error report for conditional types ([#5041](https://github.com/typescript-eslint/typescript-eslint/issues/5041)) ([0bfab6c](https://github.com/typescript-eslint/typescript-eslint/commit/0bfab6c9f5c5e243268200cf9368acf39ea099f8)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0a2e0963cfcc..d3b378e4a96e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,96 +1,109 @@ # Contributors -Thanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)): +Thanks goes to these wonderful people: - - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - + + + + + + + + + + + + + + + + +

Brad Zacher


James Henry


Armano


Oleksandr T.


Reyad Attiyat


James Henry

Brad Zacher

Armano

Josh Goldberg

Oleksandr T.

Patricio Trevino


Gareth Jones


Josh Goldberg


Nicholas C. Zakas


Jed Fox


Michaël De Boey

Reyad Attiyat

Gareth Jones

Patricio Trevino

Sosuke Suzuki

YeonJuan


Ben Lichtman


Nikita Stefaniak


Scott O'Hara


Retsam


Nicholas C. Zakas

Jed Fox

YeonJuan

Rafael Santana

Ben Lichtman

Sosuke Suzuki


Kai Cataldo


Rasmus Eneman


Toru Nagashima


Lucas Azzola


Joshua Chen

Taeheon Kim

Nikita

Scott O'Hara

Retsam

Danny Fritz


Ika


mackie


JounQin


Kanitkorn Sujautra


Kai Cataldo

Rasmus Eneman

Rebecca Stevens

Toru Nagashima

Yosuke Ota

cherryblossom000


Simen Bekkhus


Anix


Pete Gonzalez


ldrick


JounQin

Lucas Azzola

Danny Fritz

Ika

mackie

Susisu


G r e y


Gavin Barron


Kevin Partington


Lucas Duailibe


Simen Bekkhus

Kanitkorn Sujautra

cherryblossom

Daniil Dubrava

Anix

Validark


Pavel Birukov


Shahar Dawn Or


ulrichb


Daniil Dubrava


Pete Gonzalez

ldrick

Susisu

G r e y

Gavin Barron

Daniel Nixon


Denys Kniazevych


Dimitri Mitropoulos


Ian MacLeod


Jonathan Delgado


Kevin Partington

Lucas Duailibe

Validark

Pavel Birukov

Shahar Dawn Or

Philipp A.


Pig Fang


Tadhg McDonald-Jensen


Thomas den Hollander


Tim Kraut


islandryu

koooge

thomas michael wallace

ulrichb

Zzzen

Yusuke Tanaka


Zzzen


koooge


thomas michael wallace


Bence Dányi


Daniel Cassidy

Daniel Nixon

Denys Kniazevych

Dimitri Mitropoulos

Ian MacLeod

Soobin Bak


James Garbutt

Jonathan Delgado

Philipp A.

Pig Fang

Tadhg McDonald-Jensen

Thomas den Hollander

Tim Kraut

Yasar Siddiqui

Yusuke Tanaka

Bence Dányi

Eric Wang

Juan García

Soobin Bak
- - This list is auto-generated using `yarn generate-contributors`. It shows the top 100 contributors with > 3 contributions. diff --git a/docs/linting/README.md b/docs/linting/README.md index e42c436bd1d1..dbf08d1e7808 100644 --- a/docs/linting/README.md +++ b/docs/linting/README.md @@ -85,27 +85,27 @@ With that configured, open a terminal to the root of your project, and run the f ```bash -npx eslint . --ext .js,.jsx,.ts,.tsx +npx eslint . ``` ```bash -yarn eslint . --ext .js,.jsx,.ts,.tsx +yarn eslint . ``` -That's it - ESLint will lint all `.js`, `.jsx`, `.ts`, and `.tsx` files within the current folder, and will output the results to your terminal. +That's it - ESLint will lint all TypeScript compatible files within the current folder, and will output the results to your terminal. You are also recommended to add an npm script in your package.json, so you don't have to repeat the same command every time you run ESLint. ```json title="package.json" { "scripts": { - "lint": "eslint . --ext .js,.jsx,.ts,.tsx" + "lint": "eslint ." } } ``` @@ -116,6 +116,10 @@ This way, you can invoke the `lint` script directly: npm run lint ``` +:::note +If you use non-standard file extensions, you will need to explicitly tell ESLint to lint those extensions using the [`--ext` flag](https://eslint.org/docs/user-guide/command-line-interface#--ext) +::: + You can also get results in realtime inside most IDEs via a plugin - search your IDE's extension store. ## Next Steps diff --git a/docs/linting/TROUBLESHOOTING.md b/docs/linting/TROUBLESHOOTING.md index 8f8ae10565de..d6cb97486f57 100644 --- a/docs/linting/TROUBLESHOOTING.md +++ b/docs/linting/TROUBLESHOOTING.md @@ -119,17 +119,20 @@ As of our v4.0.0 release, this also applies to types. If you use global types from a 3rd party package (i.e. anything from an `@types` package), then you will have to configure ESLint appropriately to define these global types. For example; the `JSX` namespace from `@types/react` is a global 3rd party type that you must define in your ESLint config. -Note, that for a mixed project including JavaScript and TypeScript, the `no-undef` rule (like any role) can be turned off for TypeScript files alone by adding an `overrides` section to .eslintrc.json: - -```json - "overrides": [ - { - "files": ["*.ts"], - "rules": { - "no-undef": "off" - } - } - ] +Note, that for a mixed project including JavaScript and TypeScript, the `no-undef` rule (like any rule) can be turned off for TypeScript files alone by adding an `overrides` section to `.eslintrc.cjs`: + +```js title=".eslintrc.cjs" +module.exports = { + // ... the rest of your config ... + overrides: [ + { + files: ['*.ts', '*.mts', '*.cts', '*.tsx'], + rules: { + 'no-undef': 'off', + }, + }, + ], +}; ``` If you choose to leave on the ESLint `no-undef` lint rule, you can [manually define the set of allowed `globals` in your ESLint config](https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals), and/or you can use one of the [pre-defined environment (`env`) configurations](https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments). @@ -206,7 +209,7 @@ Instead of using this plugin, we recommend using prettier's `--list-different` f For example, our CI is setup to run the following command automatically, which blocks PRs that have not been formatted: ```bash npm2yarn -npm run prettier --list-different \"./**/*.{ts,js,json,md}\" +npm run prettier --list-different \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" ``` ### `eslint-plugin-import` diff --git a/lerna.json b/lerna.json index 3ebfe1032e95..1698ca617214 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "5.26.0", + "version": "5.27.0", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/package.json b/package.json index 4a5754793137..1e28e5f8d3a6 100644 --- a/package.json +++ b/package.json @@ -26,18 +26,18 @@ "check-clean-workspace-after-install": "git diff --quiet --exit-code", "check-configs": "nx run-many --target=check-configs --all --parallel", "check-docs": "nx run-many --target=check-docs --all --parallel", - "check-format": "prettier --list-different \"./**/*.{md,mdx,ts,js,tsx,jsx}\"", - "check-spelling": "cspell --config=.cspell.json \"**/*.{md,mdx,ts,js,tsx,jsx}\"", + "check-format": "prettier --list-different \"./**/*.{md,mdx,ts,mts,cts,js,cjs,mjs,tsx,jsx}\"", + "check-spelling": "cspell --config=.cspell.json \"**/*.{md,mdx,ts,mts,cts,js,cjs,mjs,tsx,jsx}\"", "clean": "lerna clean && lerna run clean", "cz": "git-cz", - "format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md,css}\"", - "generate-contributors": "yarn ts-node --transpile-only ./tools/generate-contributors.ts && yarn all-contributors generate", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\"", + "generate-contributors": "yarn ts-node --transpile-only ./tools/generate-contributors.ts", "generate-sponsors": "yarn ts-node --transpile-only ./tools/generate-sponsors.ts", "generate-website-dts": "yarn ts-node --transpile-only ./tools/generate-website-dts.ts", - "lint-fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix", + "lint-fix": "eslint . --fix", "lint-markdown-fix": "yarn lint-markdown --fix", "lint-markdown": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore", - "lint": "cross-env NODE_OPTIONS=\"--max-old-space-size=16384\" eslint . --ext .js,.jsx,.ts,.tsx", + "lint": "cross-env NODE_OPTIONS=\"--max-old-space-size=16384\" eslint .", "postinstall": "yarn husky install && yarn build", "pre-commit": "yarn lint-staged", "pre-push": "yarn check-format", @@ -56,9 +56,9 @@ }, "devDependencies": { "@babel/code-frame": "^7.16.7", - "@babel/eslint-parser": "^7.17.0", - "@babel/parser": "^7.17.0", - "@babel/types": "^7.17.10", + "@babel/eslint-parser": "^7.18.2", + "@babel/parser": "^7.18.0", + "@babel/types": "^7.18.2", "@commitlint/cli": "^16.2.4", "@commitlint/config-conventional": "^16.2.4", "@nrwl/cli": "14.1.4", @@ -82,7 +82,6 @@ "@types/rimraf": "^3.0.2", "@types/semver": "^7.3.9", "@types/tmp": "^0.2.3", - "all-contributors-cli": "^6.20.0", "cross-env": "^7.0.3", "cross-fetch": "^3.1.5", "cspell": "^5.20.0", @@ -101,7 +100,7 @@ "jest-diff": "^28.1.0", "jest-snapshot": "^28.1.0", "jest-specific-snapshot": "^5.0.0", - "lerna": "^4.0.0", + "lerna": "5.0.0", "lint-staged": "^12.4.1", "make-dir": "^3.1.0", "markdownlint-cli": "^0.31.1", @@ -112,10 +111,10 @@ "tmp": "^0.2.1", "ts-node": "^10.7.0", "tslint": "^6.1.3", - "typescript": ">=3.3.1 <4.6.0 || 4.7.1-rc" + "typescript": ">=3.3.1 <4.8.0" }, "resolutions": { - "typescript": "4.7.1-rc", + "typescript": "4.7.2", "@types/node": "^17.0.31", "pretty-format": "^28.1.0", "//": "Pin jest to v28 across the repo", diff --git a/packages/ast-spec/CHANGELOG.md b/packages/ast-spec/CHANGELOG.md index 7b5375ac92c8..a56f85403e2c 100644 --- a/packages/ast-spec/CHANGELOG.md +++ b/packages/ast-spec/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) +* [TS4.7] support type parameters for `typeof` ([#5067](https://github.com/typescript-eslint/typescript-eslint/issues/5067)) ([836de79](https://github.com/typescript-eslint/typescript-eslint/commit/836de79e8d1bff43149168cc913a4c2b60e79bf6)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/packages/ast-spec/package.json b/packages/ast-spec/package.json index cc762e151c85..23ea47e00c2c 100644 --- a/packages/ast-spec/package.json +++ b/packages/ast-spec/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/ast-spec", - "version": "5.26.0", + "version": "5.27.0", "description": "TypeScript-ESTree AST spec", "private": true, "keywords": [ @@ -33,8 +33,8 @@ "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf .rollup.cache && rimraf coverage", "clean-fixtures": "rimraf -g \"./src/**/fixtures/**/snapshots\"", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest", "typecheck": "tsc -p tsconfig.json --noEmit" }, diff --git a/packages/ast-spec/src/type/TSTypeQuery/spec.ts b/packages/ast-spec/src/type/TSTypeQuery/spec.ts index bf1cd3e192df..634c307ad2ca 100644 --- a/packages/ast-spec/src/type/TSTypeQuery/spec.ts +++ b/packages/ast-spec/src/type/TSTypeQuery/spec.ts @@ -1,8 +1,10 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; +import type { TSTypeParameterInstantiation } from '../../special/spec'; import type { EntityName } from '../../unions/EntityName'; export interface TSTypeQuery extends BaseNode { type: AST_NODE_TYPES.TSTypeQuery; exprName: EntityName; + typeParameters?: TSTypeParameterInstantiation; } diff --git a/packages/eslint-plugin-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md index 708dc230e7c0..055bf2508530 100644 --- a/packages/eslint-plugin-internal/CHANGELOG.md +++ b/packages/eslint-plugin-internal/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal diff --git a/packages/eslint-plugin-internal/package.json b/packages/eslint-plugin-internal/package.json index 9bbcb633b100..6b712f24a392 100644 --- a/packages/eslint-plugin-internal/package.json +++ b/packages/eslint-plugin-internal/package.json @@ -1,21 +1,21 @@ { "name": "@typescript-eslint/eslint-plugin-internal", - "version": "5.26.0", + "version": "5.27.0", "private": true, "main": "dist/index.js", "scripts": { "build": "tsc -b tsconfig.build.json", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { "@types/prettier": "*", - "@typescript-eslint/scope-manager": "5.26.0", - "@typescript-eslint/utils": "5.26.0", + "@typescript-eslint/scope-manager": "5.27.0", + "@typescript-eslint/utils": "5.27.0", "prettier": "*" } } diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index b03e61eb79b1..faa564020888 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 710adf382ea6..adbc60ef36f0 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "5.26.0", + "version": "5.27.0", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -32,13 +32,13 @@ "build": "tsc -b tsconfig.build.json", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/utils": "5.26.0", + "@typescript-eslint/utils": "5.27.0", "lodash": "^4.17.21" }, "peerDependencies": { @@ -48,6 +48,6 @@ }, "devDependencies": { "@types/lodash": "*", - "@typescript-eslint/parser": "5.26.0" + "@typescript-eslint/parser": "5.27.0" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 9ff900c12d32..f7a4ed973db3 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,25 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Bug Fixes + +* **eslint-plugin:** [no-type-alias] handle Template Literal Types ([#5092](https://github.com/typescript-eslint/typescript-eslint/issues/5092)) ([8febf11](https://github.com/typescript-eslint/typescript-eslint/commit/8febf11a9296d1c0d7ccdf91ef9ab92ec8dfc39c)) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) +* **eslint-plugin:** [ban-ts-comment] add descriptionFormat option ([#5026](https://github.com/typescript-eslint/typescript-eslint/issues/5026)) ([1fb31a4](https://github.com/typescript-eslint/typescript-eslint/commit/1fb31a4b3e05734f801ade0450fea33494e4d5e6)) +* **eslint-plugin:** [no-misused-promises] warn when spreading promises ([#5053](https://github.com/typescript-eslint/typescript-eslint/issues/5053)) ([61ffa9e](https://github.com/typescript-eslint/typescript-eslint/commit/61ffa9ed70e3cac6eca50a6c3cc5a0f1e7dec11c)) +* **eslint-plugin:** [space-infix-ops] missing error report for conditional types ([#5041](https://github.com/typescript-eslint/typescript-eslint/issues/5041)) ([0bfab6c](https://github.com/typescript-eslint/typescript-eslint/commit/0bfab6c9f5c5e243268200cf9368acf39ea099f8)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 999924414dde..ff85922117e5 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -59,8 +59,6 @@ You can also enable all the recommended rules for our plugin. Add `plugin:@types } ``` -**Note: Make sure to use `eslint --ext .js,.ts` since by [default](https://eslint.org/docs/user-guide/command-line-interface#--ext) `eslint` will only search for `.js` files.** - ### Recommended Configs You can also use [`eslint:recommended`](https://eslint.org/docs/rules/) (the set of rules which are recommended for all projects by the ESLint Team) with this plugin: @@ -95,94 +93,94 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int **Key**: :white_check_mark: = recommended, :lock: = strict, :wrench: = fixable, :thought_balloon: = requires type information -| Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | -| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------ | -------- | ----------------- | -| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive | :white_check_mark: | | | -| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays | :lock: | :wrench: | | -| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `@ts-` comments from being used or requires descriptions after directive | :white_check_mark: | | | -| [`@typescript-eslint/ban-tslint-comment`](./docs/rules/ban-tslint-comment.md) | Bans `// tslint:` comments from being used | :lock: | :wrench: | | -| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-indexed-object-style`](./docs/rules/consistent-indexed-object-style.md) | Enforce or disallow the use of the record type | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | :lock: | | | -| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-type-exports`](./docs/rules/consistent-type-exports.md) | Enforces consistent usage of type exports | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/consistent-type-imports`](./docs/rules/consistent-type-imports.md) | Enforces consistent usage of type imports | | :wrench: | | -| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | | -| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | | -| [`@typescript-eslint/explicit-module-boundary-types`](./docs/rules/explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | | | | -| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | | -| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order | | | | -| [`@typescript-eslint/method-signature-style`](./docs/rules/method-signature-style.md) | Enforces using a particular method signature syntax | | :wrench: | | -| [`@typescript-eslint/naming-convention`](./docs/rules/naming-convention.md) | Enforces naming conventions for everything across a codebase | | | :thought_balloon: | -| [`@typescript-eslint/no-base-to-string`](./docs/rules/no-base-to-string.md) | Requires that `.toString()` is only called on objects which provide useful information when stringified | :lock: | | :thought_balloon: | -| [`@typescript-eslint/no-confusing-non-null-assertion`](./docs/rules/no-confusing-non-null-assertion.md) | Disallow non-null assertion in locations that may be confusing | :lock: | :wrench: | | -| [`@typescript-eslint/no-confusing-void-expression`](./docs/rules/no-confusing-void-expression.md) | Requires expressions of type void to appear in statement position | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-duplicate-enum-values`](./docs/rules/no-duplicate-enum-values.md) | Disallow duplicate enum member values | :lock: | | | -| [`@typescript-eslint/no-dynamic-delete`](./docs/rules/no-dynamic-delete.md) | Disallow the delete operator with computed key expressions | :lock: | :wrench: | | -| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces | :lock: | | | -| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Requires Promise-like statements to be handled appropriately | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-invalid-void-type`](./docs/rules/no-invalid-void-type.md) | Disallows usage of `void` type outside of generic or return types | :lock: | | | -| [`@typescript-eslint/no-meaningless-void-operator`](./docs/rules/no-meaningless-void-operator.md) | Disallow the `void` operator except when used to discard a value | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :white_check_mark: | | | -| [`@typescript-eslint/no-misused-promises`](./docs/rules/no-misused-promises.md) | Avoid using Promises in places not designed to handle them | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces | :white_check_mark: | | | -| [`@typescript-eslint/no-non-null-asserted-nullish-coalescing`](./docs/rules/no-non-null-asserted-nullish-coalescing.md) | Disallows using a non-null assertion in the left operand of the nullish coalescing operator | :lock: | | | -| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./docs/rules/no-non-null-asserted-optional-chain.md) | Disallows using a non-null assertion after an optional chain expression | :white_check_mark: | | | -| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator | :white_check_mark: | | | -| [`@typescript-eslint/no-redundant-type-constituents`](./docs/rules/no-redundant-type-constituents.md) | Disallow members of unions and intersections that do nothing or override type information | | | :thought_balloon: | -| [`@typescript-eslint/no-require-imports`](./docs/rules/no-require-imports.md) | Disallows invocation of `require()` | | | | -| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` | :white_check_mark: | | | -| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases | | | | -| [`@typescript-eslint/no-unnecessary-boolean-literal-compare`](./docs/rules/no-unnecessary-boolean-literal-compare.md) | Flags unnecessary equality comparisons against boolean literals | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-condition`](./docs/rules/no-unnecessary-condition.md) | Prevents conditionals where the type is always truthy or always falsy | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-qualifier`](./docs/rules/no-unnecessary-qualifier.md) | Warns when a namespace qualifier is unnecessary | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-arguments`](./docs/rules/no-unnecessary-type-arguments.md) | Enforces that type arguments will not be used if not required | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression | :white_check_mark: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-constraint`](./docs/rules/no-unnecessary-type-constraint.md) | Disallows unnecessary constraints on generic types | :white_check_mark: | | | -| [`@typescript-eslint/no-unsafe-argument`](./docs/rules/no-unsafe-argument.md) | Disallows calling a function with an any type value | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-assignment`](./docs/rules/no-unsafe-assignment.md) | Disallows assigning any to variables and properties | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-call`](./docs/rules/no-unsafe-call.md) | Disallows calling an any type value | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-member-access`](./docs/rules/no-unsafe-member-access.md) | Disallows member access on any typed variables | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-return`](./docs/rules/no-unsafe-return.md) | Disallows returning any from a function | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-useless-empty-export`](./docs/rules/no-useless-empty-export.md) | Disallow empty exports that don't change anything in a module file | | :wrench: | | -| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements | :white_check_mark: | | | -| [`@typescript-eslint/non-nullable-type-assertion-style`](./docs/rules/non-nullable-type-assertion-style.md) | Prefers a non-null assertion over explicit type cast when possible | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/parameter-properties`](./docs/rules/parameter-properties.md) | Require or disallow the use of parameter properties in class constructors | | | | -| [`@typescript-eslint/prefer-as-const`](./docs/rules/prefer-as-const.md) | Prefer usage of `as const` over literal type | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/prefer-enum-initializers`](./docs/rules/prefer-enum-initializers.md) | Prefer initializing each enums member value | | | | -| [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | :lock: | | | -| [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Use function types instead of interfaces with call signatures | :lock: | :wrench: | | -| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-literal-enum-member`](./docs/rules/prefer-literal-enum-member.md) | Require that all enum members be literal values to prevent unintended enum member name shadow issues | :lock: | | | -| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/prefer-nullish-coalescing`](./docs/rules/prefer-nullish-coalescing.md) | Enforce the usage of the nullish coalescing operator instead of logical chaining | :lock: | | :thought_balloon: | -| [`@typescript-eslint/prefer-optional-chain`](./docs/rules/prefer-optional-chain.md) | Prefer using concise optional chain expressions instead of chained logical ands | :lock: | | | -| [`@typescript-eslint/prefer-readonly`](./docs/rules/prefer-readonly.md) | Requires that private members are marked as `readonly` if they're never modified outside of the constructor | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-readonly-parameter-types`](./docs/rules/prefer-readonly-parameter-types.md) | Requires that function parameters are typed as readonly to prevent accidental mutation of inputs | | | :thought_balloon: | -| [`@typescript-eslint/prefer-reduce-type-parameter`](./docs/rules/prefer-reduce-type-parameter.md) | Prefer using type parameter when calling `Array#reduce` instead of casting | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-return-this-type`](./docs/rules/prefer-return-this-type.md) | Enforce that `this` is used when only `this` type is returned | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-ts-expect-error`](./docs/rules/prefer-ts-expect-error.md) | Recommends using `@ts-expect-error` over `@ts-ignore` | :lock: | :wrench: | | -| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/require-array-sort-compare`](./docs/rules/require-array-sort-compare.md) | Requires `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: | -| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of string type | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/sort-type-union-intersection-members`](./docs/rules/sort-type-union-intersection-members.md) | Enforces that members of a type union/intersection are sorted alphabetically | | :wrench: | | -| [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/switch-exhaustiveness-check`](./docs/rules/switch-exhaustiveness-check.md) | Exhaustiveness checking in switch with union type | | | :thought_balloon: | -| [`@typescript-eslint/triple-slash-reference`](./docs/rules/triple-slash-reference.md) | Sets preference level for triple slash directives versus ES6-style import declarations | :white_check_mark: | | | -| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | | -| [`@typescript-eslint/typedef`](./docs/rules/typedef.md) | Requires type annotations to exist | | | | -| [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter | :lock: | | | +| Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | +| ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------ | -------- | ----------------- | +| [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive | :white_check_mark: | | | +| [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Require using either `T[]` or `Array` for arrays | :lock: | :wrench: | | +| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallow awaiting a value that is not a Thenable | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Disallow `@ts-` comments or require descriptions after directive | :white_check_mark: | | | +| [`@typescript-eslint/ban-tslint-comment`](./docs/rules/ban-tslint-comment.md) | Disallow `// tslint:` comments | :lock: | :wrench: | | +| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Disallow certain types | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Enforce that literals on classes are exposed in a consistent style | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-indexed-object-style`](./docs/rules/consistent-indexed-object-style.md) | Require or disallow the `Record` type | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforce consistent usage of type assertions | :lock: | | | +| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Enforce type definitions to consistently use either `interface` or `type` | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-type-exports`](./docs/rules/consistent-type-exports.md) | Enforce consistent usage of type exports | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/consistent-type-imports`](./docs/rules/consistent-type-imports.md) | Enforce consistent usage of type imports | | :wrench: | | +| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | | +| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | | +| [`@typescript-eslint/explicit-module-boundary-types`](./docs/rules/explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | | | | +| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | | +| [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order | | | | +| [`@typescript-eslint/method-signature-style`](./docs/rules/method-signature-style.md) | Enforce using a particular method signature syntax | | :wrench: | | +| [`@typescript-eslint/naming-convention`](./docs/rules/naming-convention.md) | Enforce naming conventions for everything across a codebase | | | :thought_balloon: | +| [`@typescript-eslint/no-base-to-string`](./docs/rules/no-base-to-string.md) | Require `.toString()` to only be called on objects which provide useful information when stringified | :lock: | | :thought_balloon: | +| [`@typescript-eslint/no-confusing-non-null-assertion`](./docs/rules/no-confusing-non-null-assertion.md) | Disallow non-null assertion in locations that may be confusing | :lock: | :wrench: | | +| [`@typescript-eslint/no-confusing-void-expression`](./docs/rules/no-confusing-void-expression.md) | Require expressions of type void to appear in statement position | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-duplicate-enum-values`](./docs/rules/no-duplicate-enum-values.md) | Disallow duplicate enum member values | :lock: | | | +| [`@typescript-eslint/no-dynamic-delete`](./docs/rules/no-dynamic-delete.md) | Disallow using the `delete` operator on computed key expressions | :lock: | :wrench: | | +| [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow the `any` type | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Disallow classes used as namespaces | :lock: | | | +| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Require Promise-like statements to be handled appropriately | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-invalid-void-type`](./docs/rules/no-invalid-void-type.md) | Disallow `void` type outside of generic or return types | :lock: | | | +| [`@typescript-eslint/no-meaningless-void-operator`](./docs/rules/no-meaningless-void-operator.md) | Disallow the `void` operator except when used to discard a value | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :white_check_mark: | | | +| [`@typescript-eslint/no-misused-promises`](./docs/rules/no-misused-promises.md) | Disallow Promises in places not designed to handle them | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow custom TypeScript modules and namespaces | :white_check_mark: | | | +| [`@typescript-eslint/no-non-null-asserted-nullish-coalescing`](./docs/rules/no-non-null-asserted-nullish-coalescing.md) | Disallow non-null assertions in the left operand of a nullish coalescing operator | :lock: | | | +| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./docs/rules/no-non-null-asserted-optional-chain.md) | Disallow non-null assertions after an optional chain expression | :white_check_mark: | | | +| [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallow non-null assertions using the `!` postfix operator | :white_check_mark: | | | +| [`@typescript-eslint/no-redundant-type-constituents`](./docs/rules/no-redundant-type-constituents.md) | Disallow members of unions and intersections that do nothing or override type information | | | :thought_balloon: | +| [`@typescript-eslint/no-require-imports`](./docs/rules/no-require-imports.md) | Disallow invocation of `require()` | | | | +| [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` | :white_check_mark: | | | +| [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow type aliases | | | | +| [`@typescript-eslint/no-unnecessary-boolean-literal-compare`](./docs/rules/no-unnecessary-boolean-literal-compare.md) | Disallow unnecessary equality comparisons against boolean literals | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-condition`](./docs/rules/no-unnecessary-condition.md) | Disallow conditionals where the type is always truthy or always falsy | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-qualifier`](./docs/rules/no-unnecessary-qualifier.md) | Disallow unnecessary namespace qualifiers | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-arguments`](./docs/rules/no-unnecessary-type-arguments.md) | Disallow type arguments that are equal to the default | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Disallow type assertions that do not change the type of an expression | :white_check_mark: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-constraint`](./docs/rules/no-unnecessary-type-constraint.md) | Disallow unnecessary constraints on generic types | :white_check_mark: | | | +| [`@typescript-eslint/no-unsafe-argument`](./docs/rules/no-unsafe-argument.md) | Disallow calling a function with a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-assignment`](./docs/rules/no-unsafe-assignment.md) | Disallow assigning a value with type `any` to variables and properties | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-call`](./docs/rules/no-unsafe-call.md) | Disallow calling a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-member-access`](./docs/rules/no-unsafe-member-access.md) | Disallow member access on a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-return`](./docs/rules/no-unsafe-return.md) | Disallow returning a value with type `any` from a function | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-useless-empty-export`](./docs/rules/no-useless-empty-export.md) | Disallow empty exports that don't change anything in a module file | | :wrench: | | +| [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallow `require` statements except in import statements | :white_check_mark: | | | +| [`@typescript-eslint/non-nullable-type-assertion-style`](./docs/rules/non-nullable-type-assertion-style.md) | Enforce non-null assertions over explicit type casts | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/parameter-properties`](./docs/rules/parameter-properties.md) | Require or disallow parameter properties in class constructors | | | | +| [`@typescript-eslint/prefer-as-const`](./docs/rules/prefer-as-const.md) | Enforce the use of `as const` over literal type | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/prefer-enum-initializers`](./docs/rules/prefer-enum-initializers.md) | Require each enum member value to be explicitly initialized | | | | +| [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Enforce the use of `for-of` loop over the standard `for` loop where possible | :lock: | | | +| [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Enforce using function types instead of interfaces with call signatures | :lock: | :wrench: | | +| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-literal-enum-member`](./docs/rules/prefer-literal-enum-member.md) | Require all enum members to be literal values | :lock: | | | +| [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/prefer-nullish-coalescing`](./docs/rules/prefer-nullish-coalescing.md) | Enforce using the nullish coalescing operator instead of logical chaining | :lock: | | :thought_balloon: | +| [`@typescript-eslint/prefer-optional-chain`](./docs/rules/prefer-optional-chain.md) | Enforce using concise optional chain expressions instead of chained logical ands | :lock: | | | +| [`@typescript-eslint/prefer-readonly`](./docs/rules/prefer-readonly.md) | Require private members to be marked as `readonly` if they're never modified outside of the constructor | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-readonly-parameter-types`](./docs/rules/prefer-readonly-parameter-types.md) | Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs | | | :thought_balloon: | +| [`@typescript-eslint/prefer-reduce-type-parameter`](./docs/rules/prefer-reduce-type-parameter.md) | Enforce using type parameter when calling `Array#reduce` instead of casting | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Enforce `RegExp#exec` over `String#match` if no global flag is provided | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-return-this-type`](./docs/rules/prefer-return-this-type.md) | Enforce that `this` is used when only `this` type is returned | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-ts-expect-error`](./docs/rules/prefer-ts-expect-error.md) | Enforce using `@ts-expect-error` over `@ts-ignore` | :lock: | :wrench: | | +| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Require any function or method that returns a Promise to be marked async | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/require-array-sort-compare`](./docs/rules/require-array-sort-compare.md) | Require `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: | +| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | Require both operands of addition to have type `number` or `string` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of `string` type | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/sort-type-union-intersection-members`](./docs/rules/sort-type-union-intersection-members.md) | Enforce members of a type union/intersection to be sorted alphabetically | | :wrench: | | +| [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Disallow certain types in boolean expressions | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/switch-exhaustiveness-check`](./docs/rules/switch-exhaustiveness-check.md) | Require switch-case statements to be exhaustive with union type | | | :thought_balloon: | +| [`@typescript-eslint/triple-slash-reference`](./docs/rules/triple-slash-reference.md) | Disallow certain triple slash directives in favor of ES6-style import declarations | :white_check_mark: | | | +| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | | +| [`@typescript-eslint/typedef`](./docs/rules/typedef.md) | Require type annotations in certain places | | | | +| [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Disallow two overloads that could be unified into one with a union or an optional/rest parameter | :lock: | | | @@ -198,13 +196,13 @@ In these cases, we create what we call an extension rule; a rule within our plug | Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------ | -------- | ----------------- | | [`@typescript-eslint/brace-style`](./docs/rules/brace-style.md) | Enforce consistent brace style for blocks | | :wrench: | | -| [`@typescript-eslint/comma-dangle`](./docs/rules/comma-dangle.md) | Require or disallow trailing comma | | :wrench: | | -| [`@typescript-eslint/comma-spacing`](./docs/rules/comma-spacing.md) | Enforces consistent spacing before and after commas | | :wrench: | | +| [`@typescript-eslint/comma-dangle`](./docs/rules/comma-dangle.md) | Require or disallow trailing commas | | :wrench: | | +| [`@typescript-eslint/comma-spacing`](./docs/rules/comma-spacing.md) | Enforce consistent spacing before and after commas | | :wrench: | | | [`@typescript-eslint/default-param-last`](./docs/rules/default-param-last.md) | Enforce default parameters to be last | | | | -| [`@typescript-eslint/dot-notation`](./docs/rules/dot-notation.md) | enforce dot notation whenever possible | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/dot-notation`](./docs/rules/dot-notation.md) | Enforce dot notation whenever possible | :lock: | :wrench: | :thought_balloon: | | [`@typescript-eslint/func-call-spacing`](./docs/rules/func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | | | [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation | | :wrench: | | -| [`@typescript-eslint/init-declarations`](./docs/rules/init-declarations.md) | require or disallow initialization in variable declarations | | | | +| [`@typescript-eslint/init-declarations`](./docs/rules/init-declarations.md) | Require or disallow initialization in variable declarations | | | | | [`@typescript-eslint/keyword-spacing`](./docs/rules/keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | | | [`@typescript-eslint/lines-between-class-members`](./docs/rules/lines-between-class-members.md) | Require or disallow an empty line between class members | | :wrench: | | | [`@typescript-eslint/no-array-constructor`](./docs/rules/no-array-constructor.md) | Disallow generic `Array` constructors | :white_check_mark: | :wrench: | | @@ -226,14 +224,14 @@ In these cases, we create what we call an extension rule; a rule within our plug | [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | | | | | [`@typescript-eslint/no-useless-constructor`](./docs/rules/no-useless-constructor.md) | Disallow unnecessary constructors | :lock: | | | | [`@typescript-eslint/object-curly-spacing`](./docs/rules/object-curly-spacing.md) | Enforce consistent spacing inside braces | | :wrench: | | -| [`@typescript-eslint/padding-line-between-statements`](./docs/rules/padding-line-between-statements.md) | require or disallow padding lines between statements | | :wrench: | | +| [`@typescript-eslint/padding-line-between-statements`](./docs/rules/padding-line-between-statements.md) | Require or disallow padding lines between statements | | :wrench: | | | [`@typescript-eslint/quotes`](./docs/rules/quotes.md) | Enforce the consistent use of either backticks, double, or single quotes | | :wrench: | | | [`@typescript-eslint/require-await`](./docs/rules/require-await.md) | Disallow async functions which have no `await` expression | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/return-await`](./docs/rules/return-await.md) | Enforces consistent returning of awaited values | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/return-await`](./docs/rules/return-await.md) | Enforce consistent returning of awaited values | | :wrench: | :thought_balloon: | | [`@typescript-eslint/semi`](./docs/rules/semi.md) | Require or disallow semicolons instead of ASI | | :wrench: | | -| [`@typescript-eslint/space-before-blocks`](./docs/rules/space-before-blocks.md) | Enforces consistent spacing before blocks | | :wrench: | | -| [`@typescript-eslint/space-before-function-paren`](./docs/rules/space-before-function-paren.md) | Enforces consistent spacing before function parenthesis | | :wrench: | | -| [`@typescript-eslint/space-infix-ops`](./docs/rules/space-infix-ops.md) | This rule is aimed at ensuring there are spaces around infix operators. | | :wrench: | | +| [`@typescript-eslint/space-before-blocks`](./docs/rules/space-before-blocks.md) | Enforce consistent spacing before blocks | | :wrench: | | +| [`@typescript-eslint/space-before-function-paren`](./docs/rules/space-before-function-paren.md) | Enforce consistent spacing before function parenthesis | | :wrench: | | +| [`@typescript-eslint/space-infix-ops`](./docs/rules/space-infix-ops.md) | Require spacing around infix operators | | :wrench: | | diff --git a/packages/eslint-plugin/docs/rules/README.md b/packages/eslint-plugin/docs/rules/README.md index 0558f7195afd..41cdb518c1cd 100644 --- a/packages/eslint-plugin/docs/rules/README.md +++ b/packages/eslint-plugin/docs/rules/README.md @@ -15,95 +15,94 @@ See [Configs](/docs/linting/configs) for how to enable recommended rules using c **Key**: :white_check_mark: = recommended, :lock: = strict, :wrench: = fixable, :thought_balloon: = requires type information -| Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | -| ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- | ------------------------ | -------- | ----------------- | -| [`@typescript-eslint/adjacent-overload-signatures`](./adjacent-overload-signatures.md) | Require that member overloads be consecutive | :white_check_mark: | | | -| [`@typescript-eslint/array-type`](./array-type.md) | Requires using either `T[]` or `Array` for arrays | :lock: | :wrench: | | -| [`@typescript-eslint/await-thenable`](./await-thenable.md) | Disallows awaiting a value that is not a Thenable | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/ban-ts-comment`](./ban-ts-comment.md) | Bans `@ts-` comments from being used or requires descriptions after directive | :white_check_mark: | | | -| [`@typescript-eslint/ban-tslint-comment`](./ban-tslint-comment.md) | Bans `// tslint:` comments from being used | :lock: | :wrench: | | -| [`@typescript-eslint/ban-types`](./ban-types.md) | Bans specific types from being used | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/class-literal-property-style`](./class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-indexed-object-style`](./consistent-indexed-object-style.md) | Enforce or disallow the use of the record type | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-type-assertions`](./consistent-type-assertions.md) | Enforces consistent usage of type assertions | :lock: | | | -| [`@typescript-eslint/consistent-type-definitions`](./consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | :lock: | :wrench: | | -| [`@typescript-eslint/consistent-type-exports`](./consistent-type-exports.md) | Enforces consistent usage of type exports | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/consistent-type-imports`](./consistent-type-imports.md) | Enforces consistent usage of type imports | | :wrench: | | -| [`@typescript-eslint/explicit-function-return-type`](./explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | | -| [`@typescript-eslint/explicit-member-accessibility`](./explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | | -| [`@typescript-eslint/explicit-module-boundary-types`](./explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | | | | -| [`@typescript-eslint/member-delimiter-style`](./member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | | -| [`@typescript-eslint/member-ordering`](./member-ordering.md) | Require a consistent member declaration order | | | | -| [`@typescript-eslint/method-signature-style`](./method-signature-style.md) | Enforces using a particular method signature syntax | | :wrench: | | -| [`@typescript-eslint/naming-convention`](./naming-convention.md) | Enforces naming conventions for everything across a codebase | | | :thought_balloon: | -| [`@typescript-eslint/no-base-to-string`](./no-base-to-string.md) | Requires that `.toString()` is only called on objects which provide useful information when stringified | :lock: | | :thought_balloon: | -| [`@typescript-eslint/no-confusing-non-null-assertion`](./no-confusing-non-null-assertion.md) | Disallow non-null assertion in locations that may be confusing | :lock: | :wrench: | | -| [`@typescript-eslint/no-confusing-void-expression`](./no-confusing-void-expression.md) | Requires expressions of type void to appear in statement position | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-duplicate-enum-values`](./no-duplicate-enum-values.md) | Disallow duplicate enum member values | :lock: | | | -| [`@typescript-eslint/no-dynamic-delete`](./no-dynamic-delete.md) | Disallow the delete operator with computed key expressions | :lock: | :wrench: | | -| [`@typescript-eslint/no-empty-interface`](./no-empty-interface.md) | Disallow the declaration of empty interfaces | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-explicit-any`](./no-explicit-any.md) | Disallow usage of the `any` type | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-extra-non-null-assertion`](./no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-extraneous-class`](./no-extraneous-class.md) | Forbids the use of classes as namespaces | :lock: | | | -| [`@typescript-eslint/no-floating-promises`](./no-floating-promises.md) | Requires Promise-like statements to be handled appropriately | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-for-in-array`](./no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-inferrable-types`](./no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/no-invalid-void-type`](./no-invalid-void-type.md) | Disallows usage of `void` type outside of generic or return types | :lock: | | | -| [`@typescript-eslint/no-meaningless-void-operator`](./no-meaningless-void-operator.md) | Disallow the `void` operator except when used to discard a value | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-misused-new`](./no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :white_check_mark: | | | -| [`@typescript-eslint/no-misused-promises`](./no-misused-promises.md) | Avoid using Promises in places not designed to handle them | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-namespace`](./no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces | :white_check_mark: | | | -| [`@typescript-eslint/no-non-null-asserted-nullish-coalescing`](./no-non-null-asserted-nullish-coalescing.md) | Disallows using a non-null assertion in the left operand of the nullish coalescing operator | :lock: | | | -| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./no-non-null-asserted-optional-chain.md) | Disallows using a non-null assertion after an optional chain expression | :white_check_mark: | | | -| [`@typescript-eslint/no-non-null-assertion`](./no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator | :white_check_mark: | | | -| [`@typescript-eslint/no-parameter-properties`](./no-parameter-properties.md) | Disallow the use of parameter properties in class constructors | | | | -| [`@typescript-eslint/no-redundant-type-constituents`](./no-redundant-type-constituents.md) | Disallow members of unions and intersections that do nothing or override type information | | | :thought_balloon: | -| [`@typescript-eslint/no-require-imports`](./no-require-imports.md) | Disallows invocation of `require()` | | | | -| [`@typescript-eslint/no-this-alias`](./no-this-alias.md) | Disallow aliasing `this` | :white_check_mark: | | | -| [`@typescript-eslint/no-type-alias`](./no-type-alias.md) | Disallow the use of type aliases | | | | -| [`@typescript-eslint/no-unnecessary-boolean-literal-compare`](./no-unnecessary-boolean-literal-compare.md) | Flags unnecessary equality comparisons against boolean literals | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-condition`](./no-unnecessary-condition.md) | Prevents conditionals where the type is always truthy or always falsy | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-qualifier`](./no-unnecessary-qualifier.md) | Warns when a namespace qualifier is unnecessary | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-arguments`](./no-unnecessary-type-arguments.md) | Enforces that type arguments will not be used if not required | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-assertion`](./no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression | :white_check_mark: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unnecessary-type-constraint`](./no-unnecessary-type-constraint.md) | Disallows unnecessary constraints on generic types | :white_check_mark: | | | -| [`@typescript-eslint/no-unsafe-argument`](./no-unsafe-argument.md) | Disallows calling a function with an any type value | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-assignment`](./no-unsafe-assignment.md) | Disallows assigning any to variables and properties | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-call`](./no-unsafe-call.md) | Disallows calling an any type value | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-member-access`](./no-unsafe-member-access.md) | Disallows member access on any typed variables | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-return`](./no-unsafe-return.md) | Disallows returning any from a function | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-useless-empty-export`](./no-useless-empty-export.md) | Disallow empty exports that don't change anything in a module file | | :wrench: | | -| [`@typescript-eslint/no-var-requires`](./no-var-requires.md) | Disallows the use of require statements except in import statements | :white_check_mark: | | | -| [`@typescript-eslint/non-nullable-type-assertion-style`](./non-nullable-type-assertion-style.md) | Prefers a non-null assertion over explicit type cast when possible | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/parameter-properties`](./parameter-properties.md) | Require or disallow the use of parameter properties in class constructors | | | | -| [`@typescript-eslint/prefer-as-const`](./prefer-as-const.md) | Prefer usage of `as const` over literal type | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/prefer-enum-initializers`](./prefer-enum-initializers.md) | Prefer initializing each enums member value | | | | -| [`@typescript-eslint/prefer-for-of`](./prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | :lock: | | | -| [`@typescript-eslint/prefer-function-type`](./prefer-function-type.md) | Use function types instead of interfaces with call signatures | :lock: | :wrench: | | -| [`@typescript-eslint/prefer-includes`](./prefer-includes.md) | Enforce `includes` method over `indexOf` method | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-literal-enum-member`](./prefer-literal-enum-member.md) | Require that all enum members be literal values to prevent unintended enum member name shadow issues | :lock: | | | -| [`@typescript-eslint/prefer-namespace-keyword`](./prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :white_check_mark: | :wrench: | | -| [`@typescript-eslint/prefer-nullish-coalescing`](./prefer-nullish-coalescing.md) | Enforce the usage of the nullish coalescing operator instead of logical chaining | :lock: | | :thought_balloon: | -| [`@typescript-eslint/prefer-optional-chain`](./prefer-optional-chain.md) | Prefer using concise optional chain expressions instead of chained logical ands | :lock: | | | -| [`@typescript-eslint/prefer-readonly`](./prefer-readonly.md) | Requires that private members are marked as `readonly` if they're never modified outside of the constructor | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-readonly-parameter-types`](./prefer-readonly-parameter-types.md) | Requires that function parameters are typed as readonly to prevent accidental mutation of inputs | | | :thought_balloon: | -| [`@typescript-eslint/prefer-reduce-type-parameter`](./prefer-reduce-type-parameter.md) | Prefer using type parameter when calling `Array#reduce` instead of casting | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-regexp-exec`](./prefer-regexp-exec.md) | Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-return-this-type`](./prefer-return-this-type.md) | Enforce that `this` is used when only `this` type is returned | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-string-starts-ends-with`](./prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | :lock: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/prefer-ts-expect-error`](./prefer-ts-expect-error.md) | Recommends using `@ts-expect-error` over `@ts-ignore` | :lock: | :wrench: | | -| [`@typescript-eslint/promise-function-async`](./promise-function-async.md) | Requires any function or method that returns a Promise to be marked async | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/require-array-sort-compare`](./require-array-sort-compare.md) | Requires `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: | -| [`@typescript-eslint/restrict-plus-operands`](./restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/restrict-template-expressions`](./restrict-template-expressions.md) | Enforce template literal expressions to be of string type | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/sort-type-union-intersection-members`](./sort-type-union-intersection-members.md) | Enforces that members of a type union/intersection are sorted alphabetically | | :wrench: | | -| [`@typescript-eslint/strict-boolean-expressions`](./strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | :wrench: | :thought_balloon: | -| [`@typescript-eslint/switch-exhaustiveness-check`](./switch-exhaustiveness-check.md) | Exhaustiveness checking in switch with union type | | | :thought_balloon: | -| [`@typescript-eslint/triple-slash-reference`](./triple-slash-reference.md) | Sets preference level for triple slash directives versus ES6-style import declarations | :white_check_mark: | | | -| [`@typescript-eslint/type-annotation-spacing`](./type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | | -| [`@typescript-eslint/typedef`](./typedef.md) | Requires type annotations to exist | | | | -| [`@typescript-eslint/unbound-method`](./unbound-method.md) | Enforces unbound methods are called with their expected scope | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/unified-signatures`](./unified-signatures.md) | Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter | :lock: | | | +| Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | +| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------ | -------- | ----------------- | +| [`@typescript-eslint/adjacent-overload-signatures`](./adjacent-overload-signatures.md) | Require that member overloads be consecutive | :white_check_mark: | | | +| [`@typescript-eslint/array-type`](./array-type.md) | Require using either `T[]` or `Array` for arrays | :lock: | :wrench: | | +| [`@typescript-eslint/await-thenable`](./await-thenable.md) | Disallow awaiting a value that is not a Thenable | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/ban-ts-comment`](./ban-ts-comment.md) | Disallow `@ts-` comments or require descriptions after directive | :white_check_mark: | | | +| [`@typescript-eslint/ban-tslint-comment`](./ban-tslint-comment.md) | Disallow `// tslint:` comments | :lock: | :wrench: | | +| [`@typescript-eslint/ban-types`](./ban-types.md) | Disallow certain types | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/class-literal-property-style`](./class-literal-property-style.md) | Enforce that literals on classes are exposed in a consistent style | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-indexed-object-style`](./consistent-indexed-object-style.md) | Require or disallow the `Record` type | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-type-assertions`](./consistent-type-assertions.md) | Enforce consistent usage of type assertions | :lock: | | | +| [`@typescript-eslint/consistent-type-definitions`](./consistent-type-definitions.md) | Enforce type definitions to consistently use either `interface` or `type` | :lock: | :wrench: | | +| [`@typescript-eslint/consistent-type-exports`](./consistent-type-exports.md) | Enforce consistent usage of type exports | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/consistent-type-imports`](./consistent-type-imports.md) | Enforce consistent usage of type imports | | :wrench: | | +| [`@typescript-eslint/explicit-function-return-type`](./explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | | +| [`@typescript-eslint/explicit-member-accessibility`](./explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | | +| [`@typescript-eslint/explicit-module-boundary-types`](./explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | | | | +| [`@typescript-eslint/member-delimiter-style`](./member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | | +| [`@typescript-eslint/member-ordering`](./member-ordering.md) | Require a consistent member declaration order | | | | +| [`@typescript-eslint/method-signature-style`](./method-signature-style.md) | Enforce using a particular method signature syntax | | :wrench: | | +| [`@typescript-eslint/naming-convention`](./naming-convention.md) | Enforce naming conventions for everything across a codebase | | | :thought_balloon: | +| [`@typescript-eslint/no-base-to-string`](./no-base-to-string.md) | Require `.toString()` to only be called on objects which provide useful information when stringified | :lock: | | :thought_balloon: | +| [`@typescript-eslint/no-confusing-non-null-assertion`](./no-confusing-non-null-assertion.md) | Disallow non-null assertion in locations that may be confusing | :lock: | :wrench: | | +| [`@typescript-eslint/no-confusing-void-expression`](./no-confusing-void-expression.md) | Require expressions of type void to appear in statement position | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-duplicate-enum-values`](./no-duplicate-enum-values.md) | Disallow duplicate enum member values | :lock: | | | +| [`@typescript-eslint/no-dynamic-delete`](./no-dynamic-delete.md) | Disallow using the `delete` operator on computed key expressions | :lock: | :wrench: | | +| [`@typescript-eslint/no-empty-interface`](./no-empty-interface.md) | Disallow the declaration of empty interfaces | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-explicit-any`](./no-explicit-any.md) | Disallow the `any` type | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-extra-non-null-assertion`](./no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-extraneous-class`](./no-extraneous-class.md) | Disallow classes used as namespaces | :lock: | | | +| [`@typescript-eslint/no-floating-promises`](./no-floating-promises.md) | Require Promise-like statements to be handled appropriately | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-for-in-array`](./no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-inferrable-types`](./no-inferrable-types.md) | Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/no-invalid-void-type`](./no-invalid-void-type.md) | Disallow `void` type outside of generic or return types | :lock: | | | +| [`@typescript-eslint/no-meaningless-void-operator`](./no-meaningless-void-operator.md) | Disallow the `void` operator except when used to discard a value | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-misused-new`](./no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :white_check_mark: | | | +| [`@typescript-eslint/no-misused-promises`](./no-misused-promises.md) | Disallow Promises in places not designed to handle them | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-namespace`](./no-namespace.md) | Disallow custom TypeScript modules and namespaces | :white_check_mark: | | | +| [`@typescript-eslint/no-non-null-asserted-nullish-coalescing`](./no-non-null-asserted-nullish-coalescing.md) | Disallow non-null assertions in the left operand of a nullish coalescing operator | :lock: | | | +| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./no-non-null-asserted-optional-chain.md) | Disallow non-null assertions after an optional chain expression | :white_check_mark: | | | +| [`@typescript-eslint/no-non-null-assertion`](./no-non-null-assertion.md) | Disallow non-null assertions using the `!` postfix operator | :white_check_mark: | | | +| [`@typescript-eslint/no-redundant-type-constituents`](./no-redundant-type-constituents.md) | Disallow members of unions and intersections that do nothing or override type information | | | :thought_balloon: | +| [`@typescript-eslint/no-require-imports`](./no-require-imports.md) | Disallow invocation of `require()` | | | | +| [`@typescript-eslint/no-this-alias`](./no-this-alias.md) | Disallow aliasing `this` | :white_check_mark: | | | +| [`@typescript-eslint/no-type-alias`](./no-type-alias.md) | Disallow type aliases | | | | +| [`@typescript-eslint/no-unnecessary-boolean-literal-compare`](./no-unnecessary-boolean-literal-compare.md) | Disallow unnecessary equality comparisons against boolean literals | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-condition`](./no-unnecessary-condition.md) | Disallow conditionals where the type is always truthy or always falsy | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-qualifier`](./no-unnecessary-qualifier.md) | Disallow unnecessary namespace qualifiers | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-arguments`](./no-unnecessary-type-arguments.md) | Disallow type arguments that are equal to the default | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-assertion`](./no-unnecessary-type-assertion.md) | Disallow type assertions that do not change the type of an expression | :white_check_mark: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/no-unnecessary-type-constraint`](./no-unnecessary-type-constraint.md) | Disallow unnecessary constraints on generic types | :white_check_mark: | | | +| [`@typescript-eslint/no-unsafe-argument`](./no-unsafe-argument.md) | Disallow calling a function with a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-assignment`](./no-unsafe-assignment.md) | Disallow assigning a value with type `any` to variables and properties | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-call`](./no-unsafe-call.md) | Disallow calling a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-member-access`](./no-unsafe-member-access.md) | Disallow member access on a value with type `any` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-return`](./no-unsafe-return.md) | Disallow returning a value with type `any` from a function | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-useless-empty-export`](./no-useless-empty-export.md) | Disallow empty exports that don't change anything in a module file | | :wrench: | | +| [`@typescript-eslint/no-var-requires`](./no-var-requires.md) | Disallow `require` statements except in import statements | :white_check_mark: | | | +| [`@typescript-eslint/non-nullable-type-assertion-style`](./non-nullable-type-assertion-style.md) | Enforce non-null assertions over explicit type casts | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/parameter-properties`](./parameter-properties.md) | Require or disallow parameter properties in class constructors | | | | +| [`@typescript-eslint/prefer-as-const`](./prefer-as-const.md) | Enforce the use of `as const` over literal type | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/prefer-enum-initializers`](./prefer-enum-initializers.md) | Require each enum member value to be explicitly initialized | | | | +| [`@typescript-eslint/prefer-for-of`](./prefer-for-of.md) | Enforce the use of `for-of` loop over the standard `for` loop where possible | :lock: | | | +| [`@typescript-eslint/prefer-function-type`](./prefer-function-type.md) | Enforce using function types instead of interfaces with call signatures | :lock: | :wrench: | | +| [`@typescript-eslint/prefer-includes`](./prefer-includes.md) | Enforce `includes` method over `indexOf` method | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-literal-enum-member`](./prefer-literal-enum-member.md) | Require all enum members to be literal values | :lock: | | | +| [`@typescript-eslint/prefer-namespace-keyword`](./prefer-namespace-keyword.md) | Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules | :white_check_mark: | :wrench: | | +| [`@typescript-eslint/prefer-nullish-coalescing`](./prefer-nullish-coalescing.md) | Enforce using the nullish coalescing operator instead of logical chaining | :lock: | | :thought_balloon: | +| [`@typescript-eslint/prefer-optional-chain`](./prefer-optional-chain.md) | Enforce using concise optional chain expressions instead of chained logical ands | :lock: | | | +| [`@typescript-eslint/prefer-readonly`](./prefer-readonly.md) | Require private members to be marked as `readonly` if they're never modified outside of the constructor | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-readonly-parameter-types`](./prefer-readonly-parameter-types.md) | Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs | | | :thought_balloon: | +| [`@typescript-eslint/prefer-reduce-type-parameter`](./prefer-reduce-type-parameter.md) | Enforce using type parameter when calling `Array#reduce` instead of casting | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-regexp-exec`](./prefer-regexp-exec.md) | Enforce `RegExp#exec` over `String#match` if no global flag is provided | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-return-this-type`](./prefer-return-this-type.md) | Enforce that `this` is used when only `this` type is returned | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-string-starts-ends-with`](./prefer-string-starts-ends-with.md) | Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-ts-expect-error`](./prefer-ts-expect-error.md) | Enforce using `@ts-expect-error` over `@ts-ignore` | :lock: | :wrench: | | +| [`@typescript-eslint/promise-function-async`](./promise-function-async.md) | Require any function or method that returns a Promise to be marked async | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/require-array-sort-compare`](./require-array-sort-compare.md) | Require `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: | +| [`@typescript-eslint/restrict-plus-operands`](./restrict-plus-operands.md) | Require both operands of addition to have type `number` or `string` | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/restrict-template-expressions`](./restrict-template-expressions.md) | Enforce template literal expressions to be of `string` type | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/sort-type-union-intersection-members`](./sort-type-union-intersection-members.md) | Enforce members of a type union/intersection to be sorted alphabetically | | :wrench: | | +| [`@typescript-eslint/strict-boolean-expressions`](./strict-boolean-expressions.md) | Disallow certain types in boolean expressions | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/switch-exhaustiveness-check`](./switch-exhaustiveness-check.md) | Require switch-case statements to be exhaustive with union type | | | :thought_balloon: | +| [`@typescript-eslint/triple-slash-reference`](./triple-slash-reference.md) | Disallow certain triple slash directives in favor of ES6-style import declarations | :white_check_mark: | | | +| [`@typescript-eslint/type-annotation-spacing`](./type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | | +| [`@typescript-eslint/typedef`](./typedef.md) | Require type annotations in certain places | | | | +| [`@typescript-eslint/unbound-method`](./unbound-method.md) | Enforce unbound methods are called with their expected scope | :white_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/unified-signatures`](./unified-signatures.md) | Disallow two overloads that could be unified into one with a union or an optional/rest parameter | :lock: | | | @@ -119,18 +118,17 @@ In these cases, we create what we call an extension rule; a rule within our plug | Name | Description | :white_check_mark::lock: | :wrench: | :thought_balloon: | | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ------------------------ | -------- | ----------------- | | [`@typescript-eslint/brace-style`](./brace-style.md) | Enforce consistent brace style for blocks | | :wrench: | | -| [`@typescript-eslint/comma-dangle`](./comma-dangle.md) | Require or disallow trailing comma | | :wrench: | | -| [`@typescript-eslint/comma-spacing`](./comma-spacing.md) | Enforces consistent spacing before and after commas | | :wrench: | | +| [`@typescript-eslint/comma-dangle`](./comma-dangle.md) | Require or disallow trailing commas | | :wrench: | | +| [`@typescript-eslint/comma-spacing`](./comma-spacing.md) | Enforce consistent spacing before and after commas | | :wrench: | | | [`@typescript-eslint/default-param-last`](./default-param-last.md) | Enforce default parameters to be last | | | | -| [`@typescript-eslint/dot-notation`](./dot-notation.md) | enforce dot notation whenever possible | :lock: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/dot-notation`](./dot-notation.md) | Enforce dot notation whenever possible | :lock: | :wrench: | :thought_balloon: | | [`@typescript-eslint/func-call-spacing`](./func-call-spacing.md) | Require or disallow spacing between function identifiers and their invocations | | :wrench: | | | [`@typescript-eslint/indent`](./indent.md) | Enforce consistent indentation | | :wrench: | | -| [`@typescript-eslint/init-declarations`](./init-declarations.md) | require or disallow initialization in variable declarations | | | | +| [`@typescript-eslint/init-declarations`](./init-declarations.md) | Require or disallow initialization in variable declarations | | | | | [`@typescript-eslint/keyword-spacing`](./keyword-spacing.md) | Enforce consistent spacing before and after keywords | | :wrench: | | | [`@typescript-eslint/lines-between-class-members`](./lines-between-class-members.md) | Require or disallow an empty line between class members | | :wrench: | | | [`@typescript-eslint/no-array-constructor`](./no-array-constructor.md) | Disallow generic `Array` constructors | :white_check_mark: | :wrench: | | | [`@typescript-eslint/no-dupe-class-members`](./no-dupe-class-members.md) | Disallow duplicate class members | | | | -| [`@typescript-eslint/no-duplicate-imports`](./no-duplicate-imports.md) | Disallow duplicate imports | | | | | [`@typescript-eslint/no-empty-function`](./no-empty-function.md) | Disallow empty functions | :white_check_mark: | | | | [`@typescript-eslint/no-extra-parens`](./no-extra-parens.md) | Disallow unnecessary parentheses | | :wrench: | | | [`@typescript-eslint/no-extra-semi`](./no-extra-semi.md) | Disallow unnecessary semicolons | :white_check_mark: | :wrench: | | @@ -148,13 +146,13 @@ In these cases, we create what we call an extension rule; a rule within our plug | [`@typescript-eslint/no-use-before-define`](./no-use-before-define.md) | Disallow the use of variables before they are defined | | | | | [`@typescript-eslint/no-useless-constructor`](./no-useless-constructor.md) | Disallow unnecessary constructors | :lock: | | | | [`@typescript-eslint/object-curly-spacing`](./object-curly-spacing.md) | Enforce consistent spacing inside braces | | :wrench: | | -| [`@typescript-eslint/padding-line-between-statements`](./padding-line-between-statements.md) | require or disallow padding lines between statements | | :wrench: | | +| [`@typescript-eslint/padding-line-between-statements`](./padding-line-between-statements.md) | Require or disallow padding lines between statements | | :wrench: | | | [`@typescript-eslint/quotes`](./quotes.md) | Enforce the consistent use of either backticks, double, or single quotes | | :wrench: | | | [`@typescript-eslint/require-await`](./require-await.md) | Disallow async functions which have no `await` expression | :white_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/return-await`](./return-await.md) | Enforces consistent returning of awaited values | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/return-await`](./return-await.md) | Enforce consistent returning of awaited values | | :wrench: | :thought_balloon: | | [`@typescript-eslint/semi`](./semi.md) | Require or disallow semicolons instead of ASI | | :wrench: | | -| [`@typescript-eslint/space-before-blocks`](./space-before-blocks.md) | Enforces consistent spacing before blocks | | :wrench: | | -| [`@typescript-eslint/space-before-function-paren`](./space-before-function-paren.md) | Enforces consistent spacing before function parenthesis | | :wrench: | | -| [`@typescript-eslint/space-infix-ops`](./space-infix-ops.md) | This rule is aimed at ensuring there are spaces around infix operators. | | :wrench: | | +| [`@typescript-eslint/space-before-blocks`](./space-before-blocks.md) | Enforce consistent spacing before blocks | | :wrench: | | +| [`@typescript-eslint/space-before-function-paren`](./space-before-function-paren.md) | Enforce consistent spacing before function parenthesis | | :wrench: | | +| [`@typescript-eslint/space-infix-ops`](./space-infix-ops.md) | Require spacing around infix operators | | :wrench: | | diff --git a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md index 840fbcdc8d40..7acea9b8be0d 100644 --- a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md +++ b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md @@ -1,6 +1,6 @@ # `adjacent-overload-signatures` -Require that member overloads be consecutive. +Requires that member overloads be consecutive. Grouping overloaded members together can improve readability of the code. diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index 8f521e919fd3..4233b7807ab9 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -1,6 +1,6 @@ # `ban-ts-comment` -Bans `@ts-` comments from being used or requires descriptions after directive. +Disallows `@ts-` comments or requires descriptions after directive. TypeScript provides several directive comments that can be used to alter how it processes files. Using these to suppress TypeScript Compiler Errors reduces the effectiveness of TypeScript overall. diff --git a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md index 6714000aba8d..88bf65ff75ba 100644 --- a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md @@ -1,6 +1,6 @@ # `ban-tslint-comment` -Bans `// tslint:` comments from being used. +Disallows `// tslint:` comments. Useful when migrating from TSLint to ESLint. Once TSLint has been removed, this rule helps locate TSLint annotations (e.g. `// tslint:disable`). diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index 3189c086a1cc..848e88a5522e 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -1,6 +1,6 @@ # `ban-types` -Bans specific types from being used. +Disallows certain types. Some builtin types have aliases, some types are considered dangerous or harmful. It's often a good idea to ban certain types to help with consistency and safety. @@ -69,7 +69,7 @@ Example configuration: // un-ban a type that's banned by default "{}": false }, - "extendsDefaults": true + "extendDefaults": true } ] } diff --git a/packages/eslint-plugin/docs/rules/brace-style.md b/packages/eslint-plugin/docs/rules/brace-style.md index c9a259cdb7ac..9701ee8ce35c 100644 --- a/packages/eslint-plugin/docs/rules/brace-style.md +++ b/packages/eslint-plugin/docs/rules/brace-style.md @@ -1,6 +1,6 @@ # `brace-style` -Enforce consistent brace style for blocks. +Enforces consistent brace style for blocks. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/class-literal-property-style.md b/packages/eslint-plugin/docs/rules/class-literal-property-style.md index 8dab1dc263b9..6590109837bb 100644 --- a/packages/eslint-plugin/docs/rules/class-literal-property-style.md +++ b/packages/eslint-plugin/docs/rules/class-literal-property-style.md @@ -1,6 +1,6 @@ # `class-literal-property-style` -Ensures that literals on classes are exposed in a consistent style. +Enforces that literals on classes are exposed in a consistent style. When writing TypeScript applications, it's typically safe to store literal values on classes using fields with the `readonly` modifier to prevent them from being reassigned. When writing TypeScript libraries that could be used by JavaScript users however, it's typically safer to expose these literals using `getter`s, since the `readonly` modifier is enforced at compile type. diff --git a/packages/eslint-plugin/docs/rules/comma-dangle.md b/packages/eslint-plugin/docs/rules/comma-dangle.md index 2ddd7f66ca0b..da0cff435505 100644 --- a/packages/eslint-plugin/docs/rules/comma-dangle.md +++ b/packages/eslint-plugin/docs/rules/comma-dangle.md @@ -1,6 +1,6 @@ # `comma-dangle` -Require or disallow trailing comma. +Requires or disallows trailing commas. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md index 6e02816695df..b0935628db62 100644 --- a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md +++ b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md @@ -1,6 +1,6 @@ # `consistent-indexed-object-style` -Enforce or disallow the use of the record type. +Requires or disallows the `Record` type. TypeScript supports defining object show keys can be flexible using an index signature. TypeScript also has a builtin type named `Record` to create an empty object defining only an index signature. For example, the following types are equal: diff --git a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md index 37f69af6c7a3..3be2359a13c4 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md @@ -1,6 +1,6 @@ # `consistent-type-definitions` -Consistent with type definition either `interface` or `type`. +Enforces type definitions to consistently use either `interface` or `type`. There are two ways to define a type. diff --git a/packages/eslint-plugin/docs/rules/default-param-last.md b/packages/eslint-plugin/docs/rules/default-param-last.md index 830d2828c012..5d28232c5ebb 100644 --- a/packages/eslint-plugin/docs/rules/default-param-last.md +++ b/packages/eslint-plugin/docs/rules/default-param-last.md @@ -1,6 +1,6 @@ # `default-param-last` -Enforce default parameters to be last. +Enforces default parameters to be last. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/dot-notation.md b/packages/eslint-plugin/docs/rules/dot-notation.md index 1256f2004fed..01331873e47d 100644 --- a/packages/eslint-plugin/docs/rules/dot-notation.md +++ b/packages/eslint-plugin/docs/rules/dot-notation.md @@ -1,6 +1,6 @@ # `dot-notation` -enforce dot notation whenever possible. +Enforces dot notation whenever possible. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index 210871ab3478..a8845d5b1586 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -1,6 +1,6 @@ # `explicit-function-return-type` -Require explicit return types on functions and class methods. +Requires explicit return types on functions and class methods. Explicit types for function return values makes it clear to any calling code what type is returned. This ensures that the return value is assigned to a variable of the correct type; or in the case @@ -95,7 +95,7 @@ const defaults = { ### Configuring in a mixed JS/TS codebase -If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.jsx` files. +If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. ```jsonc { @@ -106,7 +106,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. "overrides": [ { // enable the rule specifically for TypeScript files - "files": ["*.ts", "*.tsx"], + "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { "@typescript-eslint/explicit-function-return-type": ["error"] } diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md index 4d14797d02c1..70100a9bf832 100644 --- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md @@ -1,6 +1,6 @@ # `explicit-member-accessibility` -Require explicit accessibility modifiers on class properties and methods. +Requires explicit accessibility modifiers on class properties and methods. Leaving off accessibility modifier and making everything public can make your interface hard to use by others. @@ -39,7 +39,7 @@ const defaultOptions: Options = { ### Configuring in a mixed JS/TS codebase -If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.jsx` files. +If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. ```jsonc { @@ -50,7 +50,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. "overrides": [ { // enable the rule specifically for TypeScript files - "files": ["*.ts", "*.tsx"], + "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { "@typescript-eslint/explicit-member-accessibility": ["error"] } diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md index d968504be074..19956f0cfe8a 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md @@ -1,6 +1,6 @@ # `explicit-module-boundary-types` -Require explicit return and argument types on exported functions' and classes' public class methods. +Requires explicit return and argument types on exported functions' and classes' public class methods. Explicit types for function return values and arguments makes it clear to any calling code what is the module boundary's input and output. @@ -110,7 +110,7 @@ const defaults = { ### Configuring in a mixed JS/TS codebase -If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.jsx` files. +If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. ```jsonc { @@ -121,7 +121,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. "overrides": [ { // enable the rule specifically for TypeScript files - "files": ["*.ts", "*.tsx"], + "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { "@typescript-eslint/explicit-module-boundary-types": ["error"] } diff --git a/packages/eslint-plugin/docs/rules/func-call-spacing.md b/packages/eslint-plugin/docs/rules/func-call-spacing.md index f968cf45d2c6..cd411013659b 100644 --- a/packages/eslint-plugin/docs/rules/func-call-spacing.md +++ b/packages/eslint-plugin/docs/rules/func-call-spacing.md @@ -1,6 +1,6 @@ # `func-call-spacing` -Require or disallow spacing between function identifiers and their invocations. +Requires or disallows spacing between function identifiers and their invocations. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/indent.md b/packages/eslint-plugin/docs/rules/indent.md index aeee0ffcc121..d093ea00f5e4 100644 --- a/packages/eslint-plugin/docs/rules/indent.md +++ b/packages/eslint-plugin/docs/rules/indent.md @@ -1,6 +1,6 @@ # `indent` -Enforce consistent indentation. +Enforces consistent indentation. ## Warning diff --git a/packages/eslint-plugin/docs/rules/init-declarations.md b/packages/eslint-plugin/docs/rules/init-declarations.md index 895aa0d4dfd7..c64c009ba9cd 100644 --- a/packages/eslint-plugin/docs/rules/init-declarations.md +++ b/packages/eslint-plugin/docs/rules/init-declarations.md @@ -1,6 +1,6 @@ # `init-declarations` -require or disallow initialization in variable declarations. +Requires or disallows initialization in variable declarations. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index 446cdab3e967..b0565acbe600 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -1,6 +1,6 @@ # `keyword-spacing` -Enforce consistent spacing before and after keywords. +Enforces consistent spacing before and after keywords. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/lines-between-class-members.md b/packages/eslint-plugin/docs/rules/lines-between-class-members.md index 769e5f8d268e..8581584a0a4d 100644 --- a/packages/eslint-plugin/docs/rules/lines-between-class-members.md +++ b/packages/eslint-plugin/docs/rules/lines-between-class-members.md @@ -1,6 +1,6 @@ # `lines-between-class-members` -Require or disallow an empty line between class members. +Requires or disallows an empty line between class members. This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member. This rule require or disallow an empty line between class members. diff --git a/packages/eslint-plugin/docs/rules/member-delimiter-style.md b/packages/eslint-plugin/docs/rules/member-delimiter-style.md index 741f34171be3..644886146c13 100644 --- a/packages/eslint-plugin/docs/rules/member-delimiter-style.md +++ b/packages/eslint-plugin/docs/rules/member-delimiter-style.md @@ -1,6 +1,6 @@ # `member-delimiter-style` -Require a specific member delimiter style for interfaces and type literals. +Requires a specific member delimiter style for interfaces and type literals. Enforces a consistent member delimiter style in interfaces and type literals. There are three member delimiter styles primarily used in TypeScript: diff --git a/packages/eslint-plugin/docs/rules/member-ordering.md b/packages/eslint-plugin/docs/rules/member-ordering.md index 588fd8ada36a..19f5792dfe3a 100644 --- a/packages/eslint-plugin/docs/rules/member-ordering.md +++ b/packages/eslint-plugin/docs/rules/member-ordering.md @@ -1,6 +1,6 @@ # `member-ordering` -Require a consistent member declaration order. +Requires a consistent member declaration order. A consistent ordering of fields, methods and constructors can make interfaces, type literals, classes and class expressions easier to read, navigate, and edit. diff --git a/packages/eslint-plugin/docs/rules/no-array-constructor.md b/packages/eslint-plugin/docs/rules/no-array-constructor.md index 603ba48a5bc8..72ad9f760b86 100644 --- a/packages/eslint-plugin/docs/rules/no-array-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-array-constructor.md @@ -1,6 +1,6 @@ # `no-array-constructor` -Disallow generic `Array` constructors. +Disallows generic `Array` constructors. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-base-to-string.md b/packages/eslint-plugin/docs/rules/no-base-to-string.md index fde51eccffcd..e8e0cf85384b 100644 --- a/packages/eslint-plugin/docs/rules/no-base-to-string.md +++ b/packages/eslint-plugin/docs/rules/no-base-to-string.md @@ -1,6 +1,6 @@ # `no-base-to-string` -Requires that `.toString()` is only called on objects which provide useful information when stringified. +Requires `.toString()` to only be called on objects which provide useful information when stringified. JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals. diff --git a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md index 1f5d5b040fd3..53b1617a0a85 100644 --- a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md @@ -1,6 +1,6 @@ # `no-confusing-non-null-assertion` -Disallow non-null assertion in locations that may be confusing. +Disallows non-null assertion in locations that may be confusing. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md index e0206510e8da..3d9c774cd12d 100644 --- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md +++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md @@ -1,6 +1,6 @@ # `no-dupe-class-members` -Disallow duplicate class members. +Disallows duplicate class members. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md b/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md index c2fa1db4eec2..41fa24f4f541 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md @@ -1,6 +1,6 @@ # `no-duplicate-enum-values` -Disallow duplicate enum member values. +Disallows duplicate enum member values. Although TypeScript supports duplicate enum member values, people usually expect members to have unique values within the same enum. Duplicate values can lead to bugs that are hard to track down. diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md index ae6043468e26..74f1ebb98073 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md @@ -1,6 +1,6 @@ # `no-duplicate-imports` -Disallow duplicate imports. +Disallows duplicate imports. ## DEPRECATED diff --git a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md index abbee2acf023..2b5174e21baf 100644 --- a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md +++ b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md @@ -1,6 +1,6 @@ # `no-dynamic-delete` -Disallow the delete operator with computed key expressions. +Disallows using the `delete` operator on computed key expressions. Deleting dynamically computed keys can be dangerous and in some cases not well optimized. diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md index b25459f6a5d4..4cf87c54fb35 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-function.md +++ b/packages/eslint-plugin/docs/rules/no-empty-function.md @@ -1,6 +1,6 @@ # `no-empty-function` -Disallow empty functions. +Disallows empty functions. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-empty-interface.md b/packages/eslint-plugin/docs/rules/no-empty-interface.md index 508edd1993ce..1b3bdd6bcf59 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-interface.md +++ b/packages/eslint-plugin/docs/rules/no-empty-interface.md @@ -1,6 +1,6 @@ # `no-empty-interface` -Disallow the declaration of empty interfaces. +Disallows the declaration of empty interfaces. An empty interface is equivalent to its supertype. If the interface does not implement a supertype, then the interface is equivalent to an empty object (`{}`). In both cases it can be omitted. diff --git a/packages/eslint-plugin/docs/rules/no-explicit-any.md b/packages/eslint-plugin/docs/rules/no-explicit-any.md index aff5ae083e0e..b1f2cbcffc28 100644 --- a/packages/eslint-plugin/docs/rules/no-explicit-any.md +++ b/packages/eslint-plugin/docs/rules/no-explicit-any.md @@ -1,6 +1,6 @@ # `no-explicit-any` -Disallow usage of the `any` type. +Disallows the `any` type. Using the `any` type defeats the purpose of using TypeScript. When `any` is used, all compiler type checks around that value are ignored. diff --git a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md index 78ab63347bfe..aa5567602b06 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md @@ -1,6 +1,6 @@ # `no-extra-non-null-assertion` -Disallow extra non-null assertion. +Disallows extra non-null assertion. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-extra-parens.md b/packages/eslint-plugin/docs/rules/no-extra-parens.md index 4cccccdbe790..d2e120376419 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-parens.md +++ b/packages/eslint-plugin/docs/rules/no-extra-parens.md @@ -1,6 +1,6 @@ # `no-extra-parens` -Disallow unnecessary parentheses. +Disallows unnecessary parentheses. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-extra-semi.md b/packages/eslint-plugin/docs/rules/no-extra-semi.md index 6137b6ca21be..b2bc866d6129 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-semi.md +++ b/packages/eslint-plugin/docs/rules/no-extra-semi.md @@ -1,6 +1,6 @@ # `no-extra-semi` -Disallow unnecessary semicolons. +Disallows unnecessary semicolons. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-extraneous-class.md b/packages/eslint-plugin/docs/rules/no-extraneous-class.md index eb229ea655aa..121305b16f3f 100644 --- a/packages/eslint-plugin/docs/rules/no-extraneous-class.md +++ b/packages/eslint-plugin/docs/rules/no-extraneous-class.md @@ -1,6 +1,6 @@ # `no-extraneous-class` -Forbids the use of classes as namespaces. +Disallows classes used as namespaces. This rule warns when a class is accidentally used as a namespace. diff --git a/packages/eslint-plugin/docs/rules/no-for-in-array.md b/packages/eslint-plugin/docs/rules/no-for-in-array.md index 6c4e46b85912..4429248845c8 100644 --- a/packages/eslint-plugin/docs/rules/no-for-in-array.md +++ b/packages/eslint-plugin/docs/rules/no-for-in-array.md @@ -1,6 +1,6 @@ # `no-for-in-array` -Disallow iterating over an array with a for-in loop. +Disallows iterating over an array with a for-in loop. This rule prohibits iterating over an array with a for-in loop. diff --git a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md b/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md index 676ae450532c..4bd9c2c1b5f2 100644 --- a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md +++ b/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md @@ -1,6 +1,6 @@ # `no-implicit-any-catch` -Disallow usage of the implicit `any` type in catch clauses. +Disallows usage of the implicit `any` type in catch clauses. TypeScript 4.0 added support for adding an explicit `any` or `unknown` type annotation on a catch clause variable. diff --git a/packages/eslint-plugin/docs/rules/no-implied-eval.md b/packages/eslint-plugin/docs/rules/no-implied-eval.md index 5c59f35bb70a..74a1c3bbcabb 100644 --- a/packages/eslint-plugin/docs/rules/no-implied-eval.md +++ b/packages/eslint-plugin/docs/rules/no-implied-eval.md @@ -1,6 +1,6 @@ # `no-implied-eval` -Disallow the use of `eval()`-like methods. +Disallows the use of `eval()`-like methods. It's considered a good practice to avoid using `eval()`. There are security and performance implications involved with doing so, which is why many linters recommend disallowing `eval()`. However, there are some other ways to pass a string and have it interpreted as JavaScript code that have similar concerns. diff --git a/packages/eslint-plugin/docs/rules/no-invalid-this.md b/packages/eslint-plugin/docs/rules/no-invalid-this.md index 7681bb07f225..18b191f022d4 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-this.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-this.md @@ -1,6 +1,6 @@ # `no-invalid-this` -Disallow `this` keywords outside of classes or class-like objects. +Disallows `this` keywords outside of classes or class-like objects. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md index 44ee066b3686..545d49a297a4 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md @@ -1,6 +1,6 @@ # `no-invalid-void-type` -Disallows usage of `void` type outside of generic or return types. +Disallows `void` type outside of generic or return types. Disallows usage of `void` type outside of return types or generic type arguments. If `void` is used as return type, it shouldn’t be a part of intersection/union type with most other types. diff --git a/packages/eslint-plugin/docs/rules/no-loop-func.md b/packages/eslint-plugin/docs/rules/no-loop-func.md index 5652dc62fa52..49a88add985a 100644 --- a/packages/eslint-plugin/docs/rules/no-loop-func.md +++ b/packages/eslint-plugin/docs/rules/no-loop-func.md @@ -1,6 +1,6 @@ # `no-loop-func` -Disallow function declarations that contain unsafe references inside loop statements. +Disallows function declarations that contain unsafe references inside loop statements. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md index 4b1e8c6dd295..9ef84df7e5f9 100644 --- a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md +++ b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md @@ -1,6 +1,6 @@ # `no-loss-of-precision` -Disallow literal numbers that lose precision. +Disallows literal numbers that lose precision. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-magic-numbers.md b/packages/eslint-plugin/docs/rules/no-magic-numbers.md index ebd724b4a93e..5d1bcaf39872 100644 --- a/packages/eslint-plugin/docs/rules/no-magic-numbers.md +++ b/packages/eslint-plugin/docs/rules/no-magic-numbers.md @@ -1,6 +1,6 @@ # `no-magic-numbers` -Disallow magic numbers. +Disallows magic numbers. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md b/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md index 58b37b0888c4..13997125a85b 100644 --- a/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md +++ b/packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md @@ -1,8 +1,8 @@ # `no-meaningless-void-operator` -Disallow the `void` operator except when used to discard a value. +Disallows the `void` operator except when used to discard a value. -Disallow the `void` operator when its argument is already of type `void` or `undefined`. +Disallows the `void` operator when its argument is already of type `void` or `undefined`. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-misused-new.md b/packages/eslint-plugin/docs/rules/no-misused-new.md index 735699c6132f..f1a35f97171a 100644 --- a/packages/eslint-plugin/docs/rules/no-misused-new.md +++ b/packages/eslint-plugin/docs/rules/no-misused-new.md @@ -1,6 +1,6 @@ # `no-misused-new` -Enforce valid definition of `new` and `constructor`. +Enforces valid definition of `new` and `constructor`. Warns on apparent attempts to define constructors for interfaces or `new` for classes. diff --git a/packages/eslint-plugin/docs/rules/no-misused-promises.md b/packages/eslint-plugin/docs/rules/no-misused-promises.md index b3d5dcbe0cbf..4ae371869cd3 100644 --- a/packages/eslint-plugin/docs/rules/no-misused-promises.md +++ b/packages/eslint-plugin/docs/rules/no-misused-promises.md @@ -1,6 +1,6 @@ # `no-misused-promises` -Avoid using Promises in places not designed to handle them. +Disallows Promises in places not designed to handle them. This rule forbids providing Promises to logical locations such as if statements in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise due to a missing `await` keyword or just a misunderstanding of the way async @@ -13,9 +13,9 @@ See [`no-floating-promises`](./no-floating-promises.md) for detecting unhandled ## Rule Details -This rule accepts a single option which is an object with `checksConditionals` -and `checksVoidReturn` properties indicating which types of misuse to flag. -Both are enabled by default. +This rule accepts a single option which is an object with `checksConditionals`, +`checksVoidReturn`, and `checksSpreads` properties indicating which types of +misuse to flag. All are enabled by default. ## Options @@ -24,6 +24,7 @@ type Options = [ { checksConditionals?: boolean; checksVoidReturn?: boolean | ChecksVoidReturnOptions; + checksSpreads?: boolean; }, ]; @@ -39,6 +40,7 @@ const defaultOptions: Options = [ { checksConditionals: true, checksVoidReturn: true, + checksSpreads: true, }, ]; ``` @@ -101,6 +103,21 @@ For example, if you don't mind that passing a `() => Promise` to a `() => } ``` +### `"checksSpreads"` + +If you don't want to check object spreads, you can add this configuration: + +```json +{ + "@typescript-eslint/no-misused-promises": [ + "error", + { + "checksSpreads": false + } + ] +} +``` + ### `checksConditionals: true` Examples of code for this rule with `checksConditionals: true`: @@ -212,6 +229,42 @@ eventEmitter.on('some-event', () => { +### `checksSpreads: true` + +Examples of code for this rule with `checksSpreads: true`: + + + +#### ❌ Incorrect + +```ts +const getData = () => someAsyncOperation({ myArg: 'foo' }); + +return { foo: 42, ...getData() }; + +const getData2 = async () => { + await someAsyncOperation({ myArg: 'foo' }); +}; + +return { foo: 42, ...getData2() }; +``` + +#### ✅ Correct + +```ts +const getData = () => someAsyncOperation({ myArg: 'foo' }); + +return { foo: 42, ...(await getData()) }; + +const getData2 = async () => { + await someAsyncOperation({ myArg: 'foo' }); +}; + +return { foo: 42, ...(await getData2()) }; +``` + + + ## When Not To Use It If you do not use Promises in your codebase or are not concerned with possible diff --git a/packages/eslint-plugin/docs/rules/no-namespace.md b/packages/eslint-plugin/docs/rules/no-namespace.md index a6971b5b0b42..989bda216a49 100644 --- a/packages/eslint-plugin/docs/rules/no-namespace.md +++ b/packages/eslint-plugin/docs/rules/no-namespace.md @@ -1,6 +1,6 @@ # `no-namespace` -Disallow the use of custom TypeScript modules and namespaces. +Disallows custom TypeScript modules and namespaces. Custom TypeScript modules (`module foo {}`) and namespaces (`namespace foo {}`) are considered outdated ways to organize TypeScript code. ES2015 module syntax is now preferred (`import`/`export`). diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md index faec85a2e576..333d31f7e4da 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md @@ -1,6 +1,6 @@ # `no-non-null-asserted-nullish-coalescing` -Disallows using a non-null assertion in the left operand of the nullish coalescing operator. +Disallows non-null assertions in the left operand of a nullish coalescing operator. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md index 4772ebc9cca7..e9f3a7502770 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md @@ -1,6 +1,6 @@ # `no-non-null-asserted-optional-chain` -Disallows using a non-null assertion after an optional chain expression. +Disallows non-null assertions after an optional chain expression. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-parameter-properties.md b/packages/eslint-plugin/docs/rules/no-parameter-properties.md index 3f308256efb4..dd6fbe005178 100644 --- a/packages/eslint-plugin/docs/rules/no-parameter-properties.md +++ b/packages/eslint-plugin/docs/rules/no-parameter-properties.md @@ -1,6 +1,6 @@ # `no-parameter-properties` -Disallow the use of parameter properties in class constructors. +Disallows the use of parameter properties in class constructors. Parameter properties can be confusing to those new to TypeScript as they are less explicit than other ways of declaring and initializing class members. diff --git a/packages/eslint-plugin/docs/rules/no-redeclare.md b/packages/eslint-plugin/docs/rules/no-redeclare.md index 37859e58912c..9a8691a7af58 100644 --- a/packages/eslint-plugin/docs/rules/no-redeclare.md +++ b/packages/eslint-plugin/docs/rules/no-redeclare.md @@ -1,6 +1,6 @@ # `no-redeclare` -Disallow variable redeclaration. +Disallows variable redeclaration. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md b/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md index 3b96bd19ad19..9f15f757dfb6 100644 --- a/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md +++ b/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md @@ -1,6 +1,6 @@ # `no-redundant-type-constituents` -Disallow members of unions and intersections that do nothing or override type information. +Disallows members of unions and intersections that do nothing or override type information. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-restricted-imports.md b/packages/eslint-plugin/docs/rules/no-restricted-imports.md index 3f20d05bb2b6..683bbb78595a 100644 --- a/packages/eslint-plugin/docs/rules/no-restricted-imports.md +++ b/packages/eslint-plugin/docs/rules/no-restricted-imports.md @@ -1,6 +1,6 @@ # `no-restricted-imports` -Disallow specified modules when loaded by `import`. +Disallows specified modules when loaded by `import`. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-shadow.md b/packages/eslint-plugin/docs/rules/no-shadow.md index 4706fabe90e9..bd8500e00457 100644 --- a/packages/eslint-plugin/docs/rules/no-shadow.md +++ b/packages/eslint-plugin/docs/rules/no-shadow.md @@ -1,6 +1,6 @@ # `no-shadow` -Disallow variable declarations from shadowing variables declared in the outer scope. +Disallows variable declarations from shadowing variables declared in the outer scope. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-this-alias.md b/packages/eslint-plugin/docs/rules/no-this-alias.md index ec76dcf97a69..a49b165a57ac 100644 --- a/packages/eslint-plugin/docs/rules/no-this-alias.md +++ b/packages/eslint-plugin/docs/rules/no-this-alias.md @@ -1,6 +1,6 @@ # `no-this-alias` -Disallow aliasing `this`. +Disallows aliasing `this`. This rule prohibits assigning variables to `this`. diff --git a/packages/eslint-plugin/docs/rules/no-throw-literal.md b/packages/eslint-plugin/docs/rules/no-throw-literal.md index ff5f8bb04d16..f5c5e5bf355d 100644 --- a/packages/eslint-plugin/docs/rules/no-throw-literal.md +++ b/packages/eslint-plugin/docs/rules/no-throw-literal.md @@ -1,6 +1,6 @@ # `no-throw-literal` -Disallow throwing literals as exceptions. +Disallows throwing literals as exceptions. It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions. The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated. diff --git a/packages/eslint-plugin/docs/rules/no-type-alias.md b/packages/eslint-plugin/docs/rules/no-type-alias.md index 734c6de8d3fb..d219efd69155 100644 --- a/packages/eslint-plugin/docs/rules/no-type-alias.md +++ b/packages/eslint-plugin/docs/rules/no-type-alias.md @@ -1,6 +1,6 @@ # `no-type-alias` -Disallow the use of type aliases. +Disallows type aliases. In TypeScript, type aliases serve three purposes: @@ -118,6 +118,8 @@ type Foo = string | string[]; type Foo = string & string[]; +type Foo = `foo-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -139,6 +141,8 @@ type Foo = string; type Foo = string & string[]; +type Foo = `foo-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -156,6 +160,8 @@ type Foo = 'a' | 'b'; type Foo = string | string[]; +type Foo = `a-${number}` | `b-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -175,6 +181,8 @@ type Foo = string; type Foo = string | string[]; +type Foo = `a-${number}` | `b-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -190,6 +198,8 @@ Examples of **correct** code for the `{ "allowAliases": "in-intersections" }` op // primitives type Foo = string & string[]; +type Foo = `a-${number}` & `b-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -205,6 +215,8 @@ type Foo = 'a'; type Foo = string; +type Foo = `foo-${number}`; + // reference types interface Bar {} class Baz implements Bar {} @@ -222,6 +234,10 @@ type Foo = string | string[]; type Foo = string & string[]; +type Foo = `a-${number}` & `b-${number}`; + +type Foo = `a-${number}` | `b-${number}`; + // reference types interface Bar {} class Baz implements Bar {} diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md index a3f4316d6913..b689f9746add 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md @@ -1,6 +1,6 @@ # `no-unnecessary-boolean-literal-compare` -Flags unnecessary equality comparisons against boolean literals. +Disallows unnecessary equality comparisons against boolean literals. Comparing boolean values to boolean literals is unnecessary, those comparisons result in the same booleans. Using the boolean values directly, or via a unary negation (`!value`), is more concise and clearer. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md index 992e6d409ea5..56cc1d6b47da 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md @@ -1,6 +1,6 @@ # `no-unnecessary-condition` -Prevents conditionals where the type is always truthy or always falsy. +Disallows conditionals where the type is always truthy or always falsy. Any expression being used as a condition must be able to evaluate as truthy or falsy in order to be considered "necessary". Conversely, any expression that always evaluates to truthy or always evaluates to falsy, as determined by the type of the expression, is considered unnecessary and will be flagged by this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md index 36fc50d7fe9c..23576641f118 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md @@ -1,6 +1,6 @@ # `no-unnecessary-qualifier` -Warns when a namespace qualifier is unnecessary. +Disallows unnecessary namespace qualifiers. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md index 6473b8712642..a9383d2ef704 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md @@ -1,6 +1,6 @@ # `no-unnecessary-type-arguments` -Enforces that type arguments will not be used if not required. +Disallows type arguments that are equal to the default. Warns if an explicitly specified type argument is the default for that type parameter. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md index 66e37f70f06c..ddd5bf265277 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md @@ -1,6 +1,6 @@ # `no-unnecessary-type-assertion` -Warns if a type assertion does not change the type of an expression. +Disallows type assertions that do not change the type of an expression. This rule prohibits using a type assertion that does not change the type of an expression. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md index 2ed2f3f423ae..1d52e4034ef1 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md @@ -1,6 +1,6 @@ # `no-unsafe-argument` -Disallows calling a function with an any type value. +Disallows calling a function with a value with type `any`. Despite your best intentions, the `any` type can sometimes leak into your codebase. Call a function with `any` typed argument are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md index 12a934b25dfe..692287e9c048 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md @@ -1,6 +1,6 @@ # `no-unsafe-assignment` -Disallows assigning any to variables and properties. +Disallows assigning a value with type `any` to variables and properties. Despite your best intentions, the `any` type can sometimes leak into your codebase. Assigning an `any` typed value to a variable can be hard to pick up on, particularly if it leaks in from an external library. Operations on the variable will not be checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.md b/packages/eslint-plugin/docs/rules/no-unsafe-call.md index c883f0ff2776..61ecadc1f10b 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.md @@ -1,6 +1,6 @@ # `no-unsafe-call` -Disallows calling an any type value. +Disallows calling a value with type `any`. Despite your best intentions, the `any` type can sometimes leak into your codebase. The arguments to, and return value of calling an `any` typed variable are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md index da4b46633e5f..30eacf7339b2 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md @@ -1,6 +1,6 @@ # `no-unsafe-member-access` -Disallows member access on any typed variables. +Disallows member access on a value with type `any`. Despite your best intentions, the `any` type can sometimes leak into your codebase. Member access on `any` typed variables is not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-return.md b/packages/eslint-plugin/docs/rules/no-unsafe-return.md index 933bd5110a0f..2ba4b7ed319f 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-return.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-return.md @@ -1,6 +1,6 @@ # `no-unsafe-return` -Disallows returning any from a function. +Disallows returning a value with type `any` from a function. Despite your best intentions, the `any` type can sometimes leak into your codebase. Returned `any` typed values are not checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase. diff --git a/packages/eslint-plugin/docs/rules/no-unused-expressions.md b/packages/eslint-plugin/docs/rules/no-unused-expressions.md index cdd53d2a53d5..694c685a85fc 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-expressions.md +++ b/packages/eslint-plugin/docs/rules/no-unused-expressions.md @@ -1,6 +1,6 @@ # `no-unused-expressions` -Disallow unused expressions. +Disallows unused expressions. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-unused-vars.md b/packages/eslint-plugin/docs/rules/no-unused-vars.md index c361b263b0cd..091614902bab 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-vars.md +++ b/packages/eslint-plugin/docs/rules/no-unused-vars.md @@ -1,6 +1,6 @@ # `no-unused-vars` -Disallow unused variables. +Disallows unused variables. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-use-before-define.md b/packages/eslint-plugin/docs/rules/no-use-before-define.md index cdc1e0373916..6643cc758ae5 100644 --- a/packages/eslint-plugin/docs/rules/no-use-before-define.md +++ b/packages/eslint-plugin/docs/rules/no-use-before-define.md @@ -1,6 +1,6 @@ # `no-use-before-define` -Disallow the use of variables before they are defined. +Disallows the use of variables before they are defined. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-useless-constructor.md b/packages/eslint-plugin/docs/rules/no-useless-constructor.md index 511a81bfc491..5a0297204d2b 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-useless-constructor.md @@ -1,6 +1,6 @@ # `no-useless-constructor` -Disallow unnecessary constructors. +Disallows unnecessary constructors. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-useless-empty-export.md b/packages/eslint-plugin/docs/rules/no-useless-empty-export.md index 0042e30e97d3..f38d516de3b5 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-empty-export.md +++ b/packages/eslint-plugin/docs/rules/no-useless-empty-export.md @@ -1,6 +1,6 @@ # `no-useless-empty-export` -Disallow empty exports that don't change anything in a module file. +Disallows empty exports that don't change anything in a module file. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/no-var-requires.md b/packages/eslint-plugin/docs/rules/no-var-requires.md index 819dab59d839..d8b663059597 100644 --- a/packages/eslint-plugin/docs/rules/no-var-requires.md +++ b/packages/eslint-plugin/docs/rules/no-var-requires.md @@ -1,6 +1,6 @@ # `no-var-requires` -Disallows the use of require statements except in import statements. +Disallows `require` statements except in import statements. In other words, the use of forms such as `var foo = require("foo")` are banned. Instead use ES6 style imports or `import foo = require("foo")` imports. diff --git a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md index bebf23f28133..41ce2e4905a3 100644 --- a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md +++ b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md @@ -1,6 +1,6 @@ # `non-nullable-type-assertion-style` -Prefers a non-null assertion over explicit type cast when possible. +Enforces non-null assertions over explicit type casts. This rule detects when an `as` cast is doing the same job as a `!` would, and suggests fixing the code to be an `!`. diff --git a/packages/eslint-plugin/docs/rules/object-curly-spacing.md b/packages/eslint-plugin/docs/rules/object-curly-spacing.md index c90baead9ca7..9e9abc177e67 100644 --- a/packages/eslint-plugin/docs/rules/object-curly-spacing.md +++ b/packages/eslint-plugin/docs/rules/object-curly-spacing.md @@ -1,6 +1,6 @@ # `object-curly-spacing` -Enforce consistent spacing inside braces. +Enforces consistent spacing inside braces. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md index d8c5a29ca724..902a04fd097f 100644 --- a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md +++ b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md @@ -1,6 +1,6 @@ # `padding-line-between-statements` -require or disallow padding lines between statements. +Requires or disallows padding lines between statements. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/parameter-properties.md b/packages/eslint-plugin/docs/rules/parameter-properties.md index 773216e6cd07..c36954a829cb 100644 --- a/packages/eslint-plugin/docs/rules/parameter-properties.md +++ b/packages/eslint-plugin/docs/rules/parameter-properties.md @@ -1,6 +1,6 @@ # `parameter-properties` -Require or disallow the use of parameter properties in class constructors. +Requires or disallows parameter properties in class constructors. Parameter properties can be confusing to those new to TypeScript as they are less explicit than other ways of declaring and initializing class members. diff --git a/packages/eslint-plugin/docs/rules/prefer-as-const.md b/packages/eslint-plugin/docs/rules/prefer-as-const.md index 736f8734ec1a..0ce7b4320132 100644 --- a/packages/eslint-plugin/docs/rules/prefer-as-const.md +++ b/packages/eslint-plugin/docs/rules/prefer-as-const.md @@ -1,6 +1,6 @@ # `prefer-as-const` -Prefer usage of `as const` over literal type. +Enforces the use of `as const` over literal type. This rule recommends usage of `const` assertion when type primitive value is equal to type. diff --git a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md index 014349bc0d92..6d18d33a823c 100644 --- a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md +++ b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md @@ -1,6 +1,6 @@ # `prefer-enum-initializers` -Prefer initializing each enums member value. +Requires each enum member value to be explicitly initialized. This rule recommends having each `enum`s member value explicitly initialized. diff --git a/packages/eslint-plugin/docs/rules/prefer-for-of.md b/packages/eslint-plugin/docs/rules/prefer-for-of.md index 78fc4543e12d..52b1bbd944ec 100644 --- a/packages/eslint-plugin/docs/rules/prefer-for-of.md +++ b/packages/eslint-plugin/docs/rules/prefer-for-of.md @@ -1,6 +1,6 @@ # `prefer-for-of` -Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated. +Enforces the use of `for-of` loop over the standard `for` loop where possible. This rule recommends a for-of loop when the loop index is only used to read from an array that is being iterated. diff --git a/packages/eslint-plugin/docs/rules/prefer-function-type.md b/packages/eslint-plugin/docs/rules/prefer-function-type.md index b64b07718bb6..1025833031ff 100644 --- a/packages/eslint-plugin/docs/rules/prefer-function-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-function-type.md @@ -1,6 +1,6 @@ # `prefer-function-type` -Use function types instead of interfaces with call signatures. +Enforces using function types instead of interfaces with call signatures. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/prefer-includes.md b/packages/eslint-plugin/docs/rules/prefer-includes.md index 3c3bd628aa73..d9e355ddb632 100644 --- a/packages/eslint-plugin/docs/rules/prefer-includes.md +++ b/packages/eslint-plugin/docs/rules/prefer-includes.md @@ -1,6 +1,6 @@ # `prefer-includes` -Enforce `includes` method over `indexOf` method. +Enforces `includes` method over `indexOf` method. Until ES5, we were using `String#indexOf` method to check whether a string contains an arbitrary substring or not. Until ES2015, we were using `Array#indexOf` method to check whether an array contains an arbitrary value or not. diff --git a/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md index 65f0d8dc1a62..cec4e1f301e4 100644 --- a/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md +++ b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md @@ -1,6 +1,6 @@ # `prefer-literal-enum-member` -Require that all enum members be literal values to prevent unintended enum member name shadow issues. +Requires all enum members to be literal values. TypeScript allows the value of an enum member to be many different kinds of valid JavaScript expressions. However, because enums create their own scope whereby each enum member becomes a variable in that scope, unexpected values could be used at runtime. Example: diff --git a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md index b6ec63fd81e6..a801d1f6ba32 100644 --- a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md +++ b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md @@ -1,6 +1,6 @@ # `prefer-namespace-keyword` -Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. +Requires using `namespace` keyword over `module` keyword to declare custom TypeScript modules. In an effort to prevent further confusion between custom TypeScript modules and the new ES2015 modules, starting with TypeScript `v1.5` the keyword `namespace` is now the preferred way to declare custom TypeScript modules. diff --git a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md index 54c08e1d464b..4f9bf819ec6b 100644 --- a/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md +++ b/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md @@ -1,6 +1,6 @@ # `prefer-nullish-coalescing` -Enforce the usage of the nullish coalescing operator instead of logical chaining. +Enforces using the nullish coalescing operator instead of logical chaining. TypeScript 3.7 added support for the nullish coalescing operator. This operator allows you to safely cascade a value when dealing with `null` or `undefined`. diff --git a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md index df77f58a0e5c..9b6d3db57dc4 100644 --- a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md @@ -1,6 +1,6 @@ # `prefer-optional-chain` -Prefer using concise optional chain expressions instead of chained logical ands. +Enforces using concise optional chain expressions instead of chained logical ands. TypeScript 3.7 added support for the optional chain operator. This operator allows you to safely access properties and methods on objects when they are potentially `null` or `undefined`. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md index 82ba37fa6663..1500a084818e 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md @@ -1,6 +1,6 @@ # `prefer-readonly-parameter-types` -Requires that function parameters are typed as readonly to prevent accidental mutation of inputs. +Requires function parameters to be typed as `readonly` to prevent accidental mutation of inputs. Mutating function arguments can lead to confusing, hard to debug behavior. Whilst it's easy to implicitly remember to not modify function arguments, explicitly typing arguments as readonly provides clear contract to consumers. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly.md b/packages/eslint-plugin/docs/rules/prefer-readonly.md index 7d145515e128..b5b7b006f4ba 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly.md @@ -1,6 +1,6 @@ # `prefer-readonly` -Requires that private members are marked as `readonly` if they're never modified outside of the constructor. +Requires private members to be marked as `readonly` if they're never modified outside of the constructor. This rule enforces that private members are marked as `readonly` if they're never modified outside of the constructor. diff --git a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md index 49ef8d4330da..af69b9eaf224 100644 --- a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md +++ b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md @@ -1,6 +1,6 @@ # `prefer-reduce-type-parameter` -Prefer using type parameter when calling `Array#reduce` instead of casting. +Enforces using type parameter when calling `Array#reduce` instead of casting. It's common to call `Array#reduce` with a generic type, such as an array or object, as the initial value. Since these values are empty, their types are not usable: diff --git a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md index d4a415752f37..40a31bd877de 100644 --- a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md +++ b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md @@ -1,6 +1,6 @@ # `prefer-regexp-exec` -Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided. +Enforces `RegExp#exec` over `String#match` if no global flag is provided. As `String#match` is defined to be the same as `RegExp#exec` when the regular expression does not include the `g` flag, prefer a consistent usage. diff --git a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md index d6648458767b..590034b3e8ba 100644 --- a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md @@ -1,6 +1,6 @@ # `prefer-return-this-type` -Enforce that `this` is used when only `this` type is returned. +Enforces that `this` is used when only `this` type is returned. [Method chaining](https://en.wikipedia.org/wiki/Method_chaining) is a common pattern in OOP languages and TypeScript provides a special [polymorphic this type](https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types). If any type other than `this` is specified as the return type of these chaining methods, TypeScript will fail to cast it when invoking in subclass. diff --git a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md index 0ae2553c09d4..83b56e031877 100644 --- a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md +++ b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md @@ -1,6 +1,6 @@ # `prefer-string-starts-ends-with` -Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings. +Enforces using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings. There are multiple ways to verify if a string starts or ends with a specific string, such as `foo.indexOf('bar') === 0`. diff --git a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md index 06811604ce22..b226e13833ad 100644 --- a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md +++ b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md @@ -1,6 +1,6 @@ # `prefer-ts-expect-error` -Recommends using `@ts-expect-error` over `@ts-ignore`. +Enforces using `@ts-expect-error` over `@ts-ignore`. TypeScript allows you to suppress all errors on a line by placing a single-line comment or a comment block line starting with `@ts-ignore` immediately before the erroring line. While powerful, there is no way to know if a `@ts-ignore` is actually suppressing an error without manually investigating what happens when the `@ts-ignore` is removed. diff --git a/packages/eslint-plugin/docs/rules/promise-function-async.md b/packages/eslint-plugin/docs/rules/promise-function-async.md index 2191277b83b2..236d5a59a6d7 100644 --- a/packages/eslint-plugin/docs/rules/promise-function-async.md +++ b/packages/eslint-plugin/docs/rules/promise-function-async.md @@ -2,7 +2,6 @@ Requires any function or method that returns a Promise to be marked async. -Requires any function or method that returns a Promise to be marked async. Ensures that each function is only capable of: - returning a rejected promise, or diff --git a/packages/eslint-plugin/docs/rules/quotes.md b/packages/eslint-plugin/docs/rules/quotes.md index daaf3e509bc0..44dd33b752e1 100644 --- a/packages/eslint-plugin/docs/rules/quotes.md +++ b/packages/eslint-plugin/docs/rules/quotes.md @@ -1,6 +1,6 @@ # `quotes` -Enforce the consistent use of either backticks, double, or single quotes. +Enforces the consistent use of either backticks, double, or single quotes. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/require-await.md b/packages/eslint-plugin/docs/rules/require-await.md index c75a40803cef..c9c29c31668f 100644 --- a/packages/eslint-plugin/docs/rules/require-await.md +++ b/packages/eslint-plugin/docs/rules/require-await.md @@ -1,6 +1,6 @@ # `require-await` -Disallow async functions which have no `await` expression. +Disallows async functions which have no `await` expression. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md index d4741186e4ce..24b2a9ccd1cd 100644 --- a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md +++ b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md @@ -1,6 +1,6 @@ # `restrict-plus-operands` -When adding two variables, operands must both be of type number or of type string. +Requires both operands of addition to have type `number` or `string`. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md index 5593090a482c..0675452fce72 100644 --- a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md +++ b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md @@ -1,6 +1,6 @@ # `restrict-template-expressions` -Enforce template literal expressions to be of string type. +Enforces template literal expressions to be of `string` type. ## Rule Details diff --git a/packages/eslint-plugin/docs/rules/semi.md b/packages/eslint-plugin/docs/rules/semi.md index 7a9e125fa2b1..1dd1306626c1 100644 --- a/packages/eslint-plugin/docs/rules/semi.md +++ b/packages/eslint-plugin/docs/rules/semi.md @@ -1,6 +1,6 @@ # `semi` -Require or disallow semicolons instead of ASI. +Requires or disallows semicolons instead of ASI. This rule enforces consistent use of semicolons after statements. diff --git a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md index 49639338141d..848aa71d18bc 100644 --- a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md +++ b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md @@ -1,6 +1,6 @@ # `sort-type-union-intersection-members` -Enforces that members of a type union/intersection are sorted alphabetically. +Enforces members of a type union/intersection to be sorted alphabetically. Sorting union (`|`) and intersection (`&`) types can help: diff --git a/packages/eslint-plugin/docs/rules/space-infix-ops.md b/packages/eslint-plugin/docs/rules/space-infix-ops.md index 21dd58c312dc..96d2a111eb5b 100644 --- a/packages/eslint-plugin/docs/rules/space-infix-ops.md +++ b/packages/eslint-plugin/docs/rules/space-infix-ops.md @@ -1,6 +1,6 @@ # `space-infix-ops` -This rule is aimed at ensuring there are spaces around infix operators.. +Requires spacing around infix operators. This rule extends the base [`eslint/space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops) rule. diff --git a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md index f993881c8c22..357c2360a1fc 100644 --- a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md +++ b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md @@ -1,6 +1,6 @@ # `strict-boolean-expressions` -Restricts the types allowed in boolean expressions. +Disallows certain types in boolean expressions. Forbids usage of non-boolean types in expressions where a boolean is expected. `boolean` and `never` types are always allowed. diff --git a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md index df6fc1f72bc4..ac9d11f659b9 100644 --- a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md +++ b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md @@ -1,6 +1,6 @@ # `switch-exhaustiveness-check` -Exhaustiveness checking in switch with union type. +Requires switch-case statements to be exhaustive with union type. Union type may have a lot of parts. It's easy to forget to consider all cases in switch. This rule reminds which parts are missing. If domain of the problem requires to have only a partial switch, developer may _explicitly_ add a default clause. diff --git a/packages/eslint-plugin/docs/rules/triple-slash-reference.md b/packages/eslint-plugin/docs/rules/triple-slash-reference.md index d15d1cc5e129..4f6ef5509ef4 100644 --- a/packages/eslint-plugin/docs/rules/triple-slash-reference.md +++ b/packages/eslint-plugin/docs/rules/triple-slash-reference.md @@ -1,6 +1,6 @@ # `triple-slash-reference` -Sets preference level for triple slash directives versus ES6-style import declarations. +Disallows certain triple slash directives in favor of ES6-style import declarations. Use of triple-slash reference type directives is discouraged in favor of the newer `import` style. This rule allows you to ban use of `/// `, `/// `, or `/// ` directives. diff --git a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md index 903e9faf8194..f7df7ee15160 100644 --- a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md +++ b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md @@ -1,6 +1,6 @@ # `type-annotation-spacing` -Require consistent spacing around type annotations. +Requires consistent spacing around type annotations. Spacing around type annotations improves readability of the code. Although the most commonly used style guideline for type annotations in TypeScript prescribes adding a space after the colon, but not before it, it is subjective to the preferences of a project. For example: diff --git a/packages/eslint-plugin/docs/rules/typedef.md b/packages/eslint-plugin/docs/rules/typedef.md index cbe3bcd3cb07..9bc92f02770b 100644 --- a/packages/eslint-plugin/docs/rules/typedef.md +++ b/packages/eslint-plugin/docs/rules/typedef.md @@ -1,6 +1,6 @@ # `typedef` -Requires type annotations to exist. +Requires type annotations in certain places. TypeScript cannot always infer types for all places in code. Some locations require type annotations for their types to be inferred. diff --git a/packages/eslint-plugin/docs/rules/unified-signatures.md b/packages/eslint-plugin/docs/rules/unified-signatures.md index b308aff9d635..6818b686f8b4 100644 --- a/packages/eslint-plugin/docs/rules/unified-signatures.md +++ b/packages/eslint-plugin/docs/rules/unified-signatures.md @@ -1,6 +1,6 @@ # `unified-signatures` -Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter. +Disallows two overloads that could be unified into one with a union or an optional/rest parameter. ## Rule Details diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 9356f6b326f9..e06188317de7 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "5.26.0", + "version": "5.27.0", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -36,17 +36,17 @@ "check-configs": "jest tests/configs.test.ts --runTestsByPath --silent --runInBand", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", "generate:configs": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-configs.ts", "generate:rules-lists": "../../node_modules/.bin/ts-node --files --transpile-only tools/generate-rules-lists.ts", - "lint": "eslint . --ext .js,.ts --ignore-path ../../.eslintignore", + "lint": "eslint . --ignore-path ../../.eslintignore", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/scope-manager": "5.26.0", - "@typescript-eslint/type-utils": "5.26.0", - "@typescript-eslint/utils": "5.26.0", + "@typescript-eslint/scope-manager": "5.27.0", + "@typescript-eslint/type-utils": "5.27.0", + "@typescript-eslint/utils": "5.27.0", "debug": "^4.3.4", "functional-red-black-tree": "^1.0.1", "ignore": "^5.2.0", diff --git a/packages/eslint-plugin/src/configs/eslint-recommended.ts b/packages/eslint-plugin/src/configs/eslint-recommended.ts index 125c093b2bc2..71443e1f52ef 100644 --- a/packages/eslint-plugin/src/configs/eslint-recommended.ts +++ b/packages/eslint-plugin/src/configs/eslint-recommended.ts @@ -6,7 +6,7 @@ export = { overrides: [ { - files: ['*.ts', '*.tsx'], + files: ['*.ts', '*.tsx', '*.mts', '*.cts'], rules: { 'constructor-super': 'off', // ts(2335) & ts(2377) 'getter-return': 'off', // ts(2378) diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index fba44197a8a3..c84afee195f6 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -90,7 +90,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Requires using either `T[]` or `Array` for arrays', + description: 'Require using either `T[]` or `Array` for arrays', recommended: 'strict', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/await-thenable.ts b/packages/eslint-plugin/src/rules/await-thenable.ts index e1decc5ad3df..ab9f97da7c27 100644 --- a/packages/eslint-plugin/src/rules/await-thenable.ts +++ b/packages/eslint-plugin/src/rules/await-thenable.ts @@ -6,7 +6,7 @@ export default util.createRule({ name: 'await-thenable', meta: { docs: { - description: 'Disallows awaiting a value that is not a Thenable', + description: 'Disallow awaiting a value that is not a Thenable', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 96b01d8efc2f..e5cb60876ea3 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -1,19 +1,43 @@ import { AST_TOKEN_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; +type DirectiveConfig = + | boolean + | 'allow-with-description' + | { descriptionFormat: string }; + interface Options { - 'ts-expect-error'?: boolean | 'allow-with-description'; - 'ts-ignore'?: boolean | 'allow-with-description'; - 'ts-nocheck'?: boolean | 'allow-with-description'; - 'ts-check'?: boolean | 'allow-with-description'; + 'ts-expect-error'?: DirectiveConfig; + 'ts-ignore'?: DirectiveConfig; + 'ts-nocheck'?: DirectiveConfig; + 'ts-check'?: DirectiveConfig; minimumDescriptionLength?: number; } +const directiveConfigSchema = { + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + { + type: 'object', + properties: { + descriptionFormat: { type: 'string' }, + }, + }, + ], +}; + export const defaultMinimumDescriptionLength = 3; type MessageIds = | 'tsDirectiveComment' - | 'tsDirectiveCommentRequiresDescription'; + | 'tsDirectiveCommentRequiresDescription' + | 'tsDirectiveCommentDescriptionNotMatchPattern'; export default util.createRule<[Options], MessageIds>({ name: 'ban-ts-comment', @@ -21,7 +45,7 @@ export default util.createRule<[Options], MessageIds>({ type: 'problem', docs: { description: - 'Bans `@ts-` comments from being used or requires descriptions after directive', + 'Disallow `@ts-` comments or require descriptions after directive', recommended: 'error', }, messages: { @@ -29,55 +53,17 @@ export default util.createRule<[Options], MessageIds>({ 'Do not use "@ts-{{directive}}" because it alters compilation errors.', tsDirectiveCommentRequiresDescription: 'Include a description after the "@ts-{{directive}}" directive to explain why the @ts-{{directive}} is necessary. The description must be {{minimumDescriptionLength}} characters or longer.', + tsDirectiveCommentDescriptionNotMatchPattern: + 'The description for the "@ts-{{directive}}" directive must match the {{format}} format.', }, schema: [ { type: 'object', properties: { - 'ts-expect-error': { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - ], - }, - 'ts-ignore': { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - ], - }, - 'ts-nocheck': { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - ], - }, - 'ts-check': { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - ], - }, + 'ts-expect-error': directiveConfigSchema, + 'ts-ignore': directiveConfigSchema, + 'ts-nocheck': directiveConfigSchema, + 'ts-check': directiveConfigSchema, minimumDescriptionLength: { type: 'number', default: defaultMinimumDescriptionLength, @@ -99,25 +85,42 @@ export default util.createRule<[Options], MessageIds>({ create(context, [options]) { /* The regex used are taken from the ones used in the official TypeScript repo - - https://github.com/microsoft/TypeScript/blob/main/src/compiler/scanner.ts#L281-L289 + https://github.com/microsoft/TypeScript/blob/408c760fae66080104bc85c449282c2d207dfe8e/src/compiler/scanner.ts#L288-L296 */ const commentDirectiveRegExSingleLine = - /^\/*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/; + /^\/*\s*@ts-(?expect-error|ignore|check|nocheck)(?.*)/; const commentDirectiveRegExMultiLine = - /^\s*(?:\/|\*)*\s*@ts-(expect-error|ignore|check|nocheck)(.*)/; + /^\s*(?:\/|\*)*\s*@ts-(?expect-error|ignore|check|nocheck)(?.*)/; const sourceCode = context.getSourceCode(); + const descriptionFormats = new Map(); + for (const directive of [ + 'ts-expect-error', + 'ts-ignore', + 'ts-nocheck', + 'ts-check', + ] as const) { + const option = options[directive]; + if (typeof option === 'object' && option.descriptionFormat) { + descriptionFormats.set(directive, new RegExp(option.descriptionFormat)); + } + } + return { Program(): void { const comments = sourceCode.getAllComments(); comments.forEach(comment => { - let regExp = commentDirectiveRegExSingleLine; + const regExp = + comment.type === AST_TOKEN_TYPES.Line + ? commentDirectiveRegExSingleLine + : commentDirectiveRegExMultiLine; - if (comment.type !== AST_TOKEN_TYPES.Line) { - regExp = commentDirectiveRegExMultiLine; + const match = regExp.exec(comment.value); + if (!match) { + return; } - const [, directive, description] = regExp.exec(comment.value) ?? []; + const { directive, description } = match.groups!; const fullDirective = `ts-${directive}` as keyof Options; @@ -130,16 +133,26 @@ export default util.createRule<[Options], MessageIds>({ }); } - if (option === 'allow-with-description') { + if ( + option === 'allow-with-description' || + (typeof option === 'object' && option.descriptionFormat) + ) { const { minimumDescriptionLength = defaultMinimumDescriptionLength, } = options; + const format = descriptionFormats.get(fullDirective); if (description.trim().length < minimumDescriptionLength) { context.report({ data: { directive, minimumDescriptionLength }, node: comment, messageId: 'tsDirectiveCommentRequiresDescription', }); + } else if (format && !format.test(description)) { + context.report({ + data: { directive, format: format.source }, + node: comment, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + }); } } }); diff --git a/packages/eslint-plugin/src/rules/ban-tslint-comment.ts b/packages/eslint-plugin/src/rules/ban-tslint-comment.ts index 87e500d3c23a..144a46202576 100644 --- a/packages/eslint-plugin/src/rules/ban-tslint-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-tslint-comment.ts @@ -19,7 +19,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Bans `// tslint:` comments from being used', + description: 'Disallow `// tslint:` comments', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 00279a7db0c3..16b73f2cf5b2 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -117,7 +117,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Bans specific types from being used', + description: 'Disallow certain types', recommended: 'error', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/class-literal-property-style.ts b/packages/eslint-plugin/src/rules/class-literal-property-style.ts index 49c28fbd3a99..1dc876a821b3 100644 --- a/packages/eslint-plugin/src/rules/class-literal-property-style.ts +++ b/packages/eslint-plugin/src/rules/class-literal-property-style.ts @@ -40,7 +40,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Ensures that literals on classes are exposed in a consistent style', + 'Enforce that literals on classes are exposed in a consistent style', recommended: 'strict', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/comma-dangle.ts b/packages/eslint-plugin/src/rules/comma-dangle.ts index 241b35272846..f3986151489f 100644 --- a/packages/eslint-plugin/src/rules/comma-dangle.ts +++ b/packages/eslint-plugin/src/rules/comma-dangle.ts @@ -41,7 +41,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: 'Require or disallow trailing comma', + description: 'Require or disallow trailing commas', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/comma-spacing.ts b/packages/eslint-plugin/src/rules/comma-spacing.ts index 336017db1b37..ac9520440f3c 100644 --- a/packages/eslint-plugin/src/rules/comma-spacing.ts +++ b/packages/eslint-plugin/src/rules/comma-spacing.ts @@ -19,7 +19,7 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforces consistent spacing before and after commas', + description: 'Enforce consistent spacing before and after commas', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts index b68b2eae4b05..3da9692df9e2 100644 --- a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts +++ b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts @@ -9,7 +9,7 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforce or disallow the use of the record type', + description: 'Require or disallow the `Record` type', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts index 8890007f8f02..6626b728afbb 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts @@ -22,7 +22,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforces consistent usage of type assertions', + description: 'Enforce consistent usage of type assertions', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/consistent-type-definitions.ts b/packages/eslint-plugin/src/rules/consistent-type-definitions.ts index e0690e650d4c..80fd0ffafa72 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-definitions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-definitions.ts @@ -12,7 +12,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Consistent with type definition either `interface` or `type`', + 'Enforce type definitions to consistently use either `interface` or `type`', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/consistent-type-exports.ts b/packages/eslint-plugin/src/rules/consistent-type-exports.ts index 36fa561bcb3b..7d504103dbc1 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-exports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-exports.ts @@ -37,7 +37,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforces consistent usage of type exports', + description: 'Enforce consistent usage of type exports', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 6badf04d4dd6..ce642b64a92e 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -56,7 +56,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforces consistent usage of type imports', + description: 'Enforce consistent usage of type imports', recommended: false, }, messages: { diff --git a/packages/eslint-plugin/src/rules/dot-notation.ts b/packages/eslint-plugin/src/rules/dot-notation.ts index cfa8ae55a441..8b9d82d63628 100644 --- a/packages/eslint-plugin/src/rules/dot-notation.ts +++ b/packages/eslint-plugin/src/rules/dot-notation.ts @@ -19,7 +19,7 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: 'enforce dot notation whenever possible', + description: 'Enforce dot notation whenever possible', recommended: 'strict', extendsBaseRule: true, requiresTypeChecking: true, diff --git a/packages/eslint-plugin/src/rules/init-declarations.ts b/packages/eslint-plugin/src/rules/init-declarations.ts index a10035c06911..df20ff572a24 100644 --- a/packages/eslint-plugin/src/rules/init-declarations.ts +++ b/packages/eslint-plugin/src/rules/init-declarations.ts @@ -17,7 +17,7 @@ export default createRule({ type: 'suggestion', docs: { description: - 'require or disallow initialization in variable declarations', + 'Require or disallow initialization in variable declarations', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/method-signature-style.ts b/packages/eslint-plugin/src/rules/method-signature-style.ts index 032b33dc0fdd..6e744753aa90 100644 --- a/packages/eslint-plugin/src/rules/method-signature-style.ts +++ b/packages/eslint-plugin/src/rules/method-signature-style.ts @@ -9,7 +9,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Enforces using a particular method signature syntax', + description: 'Enforce using a particular method signature syntax', recommended: false, }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index cc2fa807687e..a27d9b09df0f 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -52,7 +52,7 @@ export default util.createRule({ meta: { docs: { description: - 'Enforces naming conventions for everything across a codebase', + 'Enforce naming conventions for everything across a codebase', recommended: false, // technically only requires type checking if the user uses "type" modifiers requiresTypeChecking: true, diff --git a/packages/eslint-plugin/src/rules/no-base-to-string.ts b/packages/eslint-plugin/src/rules/no-base-to-string.ts index c728f0f726b4..3cb099e7cfca 100644 --- a/packages/eslint-plugin/src/rules/no-base-to-string.ts +++ b/packages/eslint-plugin/src/rules/no-base-to-string.ts @@ -21,7 +21,7 @@ export default util.createRule({ meta: { docs: { description: - 'Requires that `.toString()` is only called on objects which provide useful information when stringified', + 'Require `.toString()` to only be called on objects which provide useful information when stringified', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts index 0fed18413bd8..15b152c00022 100644 --- a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts +++ b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts @@ -25,7 +25,7 @@ export default util.createRule({ meta: { docs: { description: - 'Requires expressions of type void to appear in statement position', + 'Require expressions of type void to appear in statement position', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-dynamic-delete.ts b/packages/eslint-plugin/src/rules/no-dynamic-delete.ts index 01ed32d74617..1654b2d2c69b 100644 --- a/packages/eslint-plugin/src/rules/no-dynamic-delete.ts +++ b/packages/eslint-plugin/src/rules/no-dynamic-delete.ts @@ -6,7 +6,8 @@ export default util.createRule({ name: 'no-dynamic-delete', meta: { docs: { - description: 'Disallow the delete operator with computed key expressions', + description: + 'Disallow using the `delete` operator on computed key expressions', recommended: 'strict', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/no-explicit-any.ts b/packages/eslint-plugin/src/rules/no-explicit-any.ts index 8617ab0bdbe7..e0e8bfd2b9cf 100644 --- a/packages/eslint-plugin/src/rules/no-explicit-any.ts +++ b/packages/eslint-plugin/src/rules/no-explicit-any.ts @@ -14,7 +14,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Disallow usage of the `any` type', + description: 'Disallow the `any` type', recommended: 'warn', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index b695301af329..f280780ef89c 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -16,7 +16,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Forbids the use of classes as namespaces', + description: 'Disallow classes used as namespaces', recommended: 'strict', }, schema: [ diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 9d991337ef58..c59d0f08a6ef 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -18,7 +18,7 @@ export default util.createRule({ meta: { docs: { description: - 'Requires Promise-like statements to be handled appropriately', + 'Require Promise-like statements to be handled appropriately', recommended: 'error', suggestion: true, requiresTypeChecking: true, diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index dc3216f4f603..9adb4bca9ecd 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -16,7 +16,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean', + 'Disallow explicit type declarations for variables or parameters initialized to a number, string, or boolean', recommended: 'error', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts index cefea8cf0c3c..a6e798217cae 100644 --- a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts +++ b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts @@ -18,8 +18,7 @@ export default util.createRule<[Options], MessageIds>({ meta: { type: 'problem', docs: { - description: - 'Disallows usage of `void` type outside of generic or return types', + description: 'Disallow `void` type outside of generic or return types', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index 03b166ec49b0..89804bf001b2 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -8,6 +8,7 @@ type Options = [ { checksConditionals?: boolean; checksVoidReturn?: boolean | ChecksVoidReturnOptions; + checksSpreads?: boolean; }, ]; @@ -25,7 +26,8 @@ type MessageId = | 'voidReturnVariable' | 'voidReturnProperty' | 'voidReturnReturnValue' - | 'voidReturnAttribute'; + | 'voidReturnAttribute' + | 'spread'; function parseChecksVoidReturn( checksVoidReturn: boolean | ChecksVoidReturnOptions | undefined, @@ -59,7 +61,7 @@ export default util.createRule({ name: 'no-misused-promises', meta: { docs: { - description: 'Avoid using Promises in places not designed to handle them', + description: 'Disallow Promises in places not designed to handle them', recommended: 'error', requiresTypeChecking: true, }, @@ -75,6 +77,7 @@ export default util.createRule({ voidReturnAttribute: 'Promise-returning function provided to attribute where a void return was expected.', conditional: 'Expected non-Promise value in a boolean conditional.', + spread: 'Expected a non-Promise value to be spreaded in an object.', }, schema: [ { @@ -99,6 +102,9 @@ export default util.createRule({ }, ], }, + checksSpreads: { + type: 'boolean', + }, }, }, ], @@ -108,10 +114,11 @@ export default util.createRule({ { checksConditionals: true, checksVoidReturn: true, + checksSpreads: true, }, ], - create(context, [{ checksConditionals, checksVoidReturn }]) { + create(context, [{ checksConditionals, checksVoidReturn, checksSpreads }]) { const parserServices = util.getParserServices(context); const checker = parserServices.program.getTypeChecker(); @@ -153,6 +160,10 @@ export default util.createRule({ } : {}; + const spreadChecks: TSESLint.RuleListener = { + SpreadElement: checkSpread, + }; + function checkTestConditional(node: { test: TSESTree.Expression | null; }): void { @@ -376,13 +387,37 @@ export default util.createRule({ } } + function checkSpread(node: TSESTree.SpreadElement): void { + const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); + + if (isSometimesThenable(checker, tsNode.expression)) { + context.report({ + messageId: 'spread', + node: node.argument, + }); + } + } + return { ...(checksConditionals ? conditionalChecks : {}), ...(checksVoidReturn ? voidReturnChecks : {}), + ...(checksSpreads ? spreadChecks : {}), }; }, }); +function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean { + const type = checker.getTypeAtLocation(node); + + for (const subType of tsutils.unionTypeParts(checker.getApparentType(type))) { + if (tsutils.isThenableType(checker, node, subType)) { + return true; + } + } + + return false; +} + // Variation on the thenable check which requires all forms of the type (read: // alternates in a union) to be thenable. Otherwise, you might be trying to // check if something is defined or undefined and get caught because one of the diff --git a/packages/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index c7183444e8b8..2a840fda3143 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -14,8 +14,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: - 'Disallow the use of custom TypeScript modules and namespaces', + description: 'Disallow custom TypeScript modules and namespaces', recommended: 'error', }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-non-null-asserted-nullish-coalescing.ts b/packages/eslint-plugin/src/rules/no-non-null-asserted-nullish-coalescing.ts index fada84c9a830..518b3e739f2c 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-asserted-nullish-coalescing.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-asserted-nullish-coalescing.ts @@ -34,7 +34,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Disallows using a non-null assertion in the left operand of the nullish coalescing operator', + 'Disallow non-null assertions in the left operand of a nullish coalescing operator', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts index 979b0af394cb..9e1b3c94656e 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts @@ -17,7 +17,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Disallows using a non-null assertion after an optional chain expression', + 'Disallow non-null assertions after an optional chain expression', recommended: 'error', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts index 296973999311..c92c31e517a8 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts @@ -9,7 +9,7 @@ export default util.createRule<[], MessageIds>({ type: 'problem', docs: { description: - 'Disallows non-null assertions using the `!` postfix operator', + 'Disallow non-null assertions using the `!` postfix operator', recommended: 'warn', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 3ef5ecc0df3a..ba899d6b7049 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -6,7 +6,7 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: 'Disallows invocation of `require()`', + description: 'Disallow invocation of `require()`', recommended: false, }, schema: [], diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index 2d9847eb3094..ba656ea4124a 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -46,7 +46,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Disallow the use of type aliases', + description: 'Disallow type aliases', // too opinionated to be recommended recommended: false, }, @@ -133,6 +133,7 @@ export default util.createRule({ AST_NODE_TYPES.TSLiteralType, AST_NODE_TYPES.TSTypeQuery, AST_NODE_TYPES.TSIndexedAccessType, + AST_NODE_TYPES.TSTemplateLiteralType, ]); /** diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts index 1bd58206285e..d135b3dd18a9 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts @@ -34,7 +34,7 @@ export default util.createRule({ meta: { docs: { description: - 'Flags unnecessary equality comparisons against boolean literals', + 'Disallow unnecessary equality comparisons against boolean literals', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index 53c440442f52..df6580be86a6 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -89,7 +89,7 @@ export default createRule({ type: 'suggestion', docs: { description: - 'Prevents conditionals where the type is always truthy or always falsy', + 'Disallow conditionals where the type is always truthy or always falsy', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts index dae21746efc8..f56aa2660b32 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts @@ -7,7 +7,7 @@ export default util.createRule({ name: 'no-unnecessary-qualifier', meta: { docs: { - description: 'Warns when a namespace qualifier is unnecessary', + description: 'Disallow unnecessary namespace qualifiers', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts index 24ac41558adb..4a8acc9bd1c1 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts @@ -21,8 +21,7 @@ export default util.createRule<[], MessageIds>({ name: 'no-unnecessary-type-arguments', meta: { docs: { - description: - 'Enforces that type arguments will not be used if not required', + description: 'Disallow type arguments that are equal to the default', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 297460965be1..d9ef180abd5f 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -21,7 +21,7 @@ export default util.createRule({ meta: { docs: { description: - 'Warns if a type assertion does not change the type of an expression', + 'Disallow type assertions that do not change the type of an expression', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts index 3987d957dd1e..bb1c9333c9bc 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts @@ -29,7 +29,7 @@ export default util.createRule({ name: 'no-unnecessary-type-constraint', meta: { docs: { - description: 'Disallows unnecessary constraints on generic types', + description: 'Disallow unnecessary constraints on generic types', recommended: 'error', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unsafe-argument.ts b/packages/eslint-plugin/src/rules/no-unsafe-argument.ts index 1c3796ad51f4..867b9c946274 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-argument.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-argument.ts @@ -134,7 +134,7 @@ export default util.createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallows calling a function with an any type value', + description: 'Disallow calling a function with a value with type `any`', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts index 10133b82d93e..00f60c6f2ac4 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts @@ -18,7 +18,8 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: 'Disallows assigning any to variables and properties', + description: + 'Disallow assigning a value with type `any` to variables and properties', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index d062aa28cadc..799bba94295d 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -14,7 +14,7 @@ export default util.createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallows calling an any type value', + description: 'Disallow calling a value with type `any`', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts index 4a930890d881..c3d55e3a5bc1 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts @@ -13,7 +13,7 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: 'Disallows member access on any typed variables', + description: 'Disallow member access on a value with type `any`', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index 8e9e4099cada..d313d1837268 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -8,7 +8,7 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: 'Disallows returning any from a function', + description: 'Disallow returning a value with type `any` from a function', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-var-requires.ts b/packages/eslint-plugin/src/rules/no-var-requires.ts index 36f0e7515d1f..9942b2108ce9 100644 --- a/packages/eslint-plugin/src/rules/no-var-requires.ts +++ b/packages/eslint-plugin/src/rules/no-var-requires.ts @@ -9,8 +9,7 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: - 'Disallows the use of require statements except in import statements', + description: 'Disallow `require` statements except in import statements', recommended: 'error', }, messages: { diff --git a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts index d2973e75808e..ce160c66e076 100644 --- a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts +++ b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts @@ -8,8 +8,7 @@ export default util.createRule({ name: 'non-nullable-type-assertion-style', meta: { docs: { - description: - 'Prefers a non-null assertion over explicit type cast when possible', + description: 'Enforce non-null assertions over explicit type casts', recommended: 'strict', requiresTypeChecking: true, suggestion: true, diff --git a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts index bc5f30aa7512..e9d62632c820 100644 --- a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts +++ b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts @@ -587,7 +587,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: 'require or disallow padding lines between statements', + description: 'Require or disallow padding lines between statements', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/parameter-properties.ts b/packages/eslint-plugin/src/rules/parameter-properties.ts index 4e3532a2fc7b..58d834088977 100644 --- a/packages/eslint-plugin/src/rules/parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/parameter-properties.ts @@ -27,7 +27,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Require or disallow the use of parameter properties in class constructors', + 'Require or disallow parameter properties in class constructors', recommended: false, }, messages: { diff --git a/packages/eslint-plugin/src/rules/prefer-as-const.ts b/packages/eslint-plugin/src/rules/prefer-as-const.ts index 09bd8423c22f..ca6b99216564 100644 --- a/packages/eslint-plugin/src/rules/prefer-as-const.ts +++ b/packages/eslint-plugin/src/rules/prefer-as-const.ts @@ -6,7 +6,7 @@ export default util.createRule({ meta: { type: 'suggestion', docs: { - description: 'Prefer usage of `as const` over literal type', + description: 'Enforce the use of `as const` over literal type', recommended: 'error', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-enum-initializers.ts b/packages/eslint-plugin/src/rules/prefer-enum-initializers.ts index c6247abd7390..bad327a5be2d 100644 --- a/packages/eslint-plugin/src/rules/prefer-enum-initializers.ts +++ b/packages/eslint-plugin/src/rules/prefer-enum-initializers.ts @@ -8,7 +8,8 @@ export default util.createRule<[], MessageIds>({ meta: { type: 'suggestion', docs: { - description: 'Prefer initializing each enums member value', + description: + 'Require each enum member value to be explicitly initialized', recommended: false, suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-for-of.ts b/packages/eslint-plugin/src/rules/prefer-for-of.ts index 97c33878acc9..c5cde3227bc3 100644 --- a/packages/eslint-plugin/src/rules/prefer-for-of.ts +++ b/packages/eslint-plugin/src/rules/prefer-for-of.ts @@ -7,7 +7,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated', + 'Enforce the use of `for-of` loop over the standard `for` loop where possible', recommended: 'strict', }, messages: { diff --git a/packages/eslint-plugin/src/rules/prefer-function-type.ts b/packages/eslint-plugin/src/rules/prefer-function-type.ts index 4c4a48120697..b5d2875e01ca 100644 --- a/packages/eslint-plugin/src/rules/prefer-function-type.ts +++ b/packages/eslint-plugin/src/rules/prefer-function-type.ts @@ -16,7 +16,7 @@ export default util.createRule({ meta: { docs: { description: - 'Use function types instead of interfaces with call signatures', + 'Enforce using function types instead of interfaces with call signatures', recommended: 'strict', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts b/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts index 17a657d7b256..625c11627f82 100644 --- a/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts +++ b/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts @@ -6,8 +6,7 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: - 'Require that all enum members be literal values to prevent unintended enum member name shadow issues', + description: 'Require all enum members to be literal values', recommended: 'strict', requiresTypeChecking: false, }, diff --git a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts index 769a0cd6e39a..bf74d5bf13ea 100644 --- a/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts +++ b/packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts @@ -7,7 +7,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules', + 'Require using `namespace` keyword over `module` keyword to declare custom TypeScript modules', recommended: 'error', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts index ddb68d90c47c..c1676d3fd323 100644 --- a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts +++ b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts @@ -20,7 +20,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Enforce the usage of the nullish coalescing operator instead of logical chaining', + 'Enforce using the nullish coalescing operator instead of logical chaining', recommended: 'strict', suggestion: true, requiresTypeChecking: true, diff --git a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts index fcf3fa782aa4..04cd7e649933 100644 --- a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts @@ -34,7 +34,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Prefer using concise optional chain expressions instead of chained logical ands', + 'Enforce using concise optional chain expressions instead of chained logical ands', recommended: 'strict', suggestion: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts b/packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts index 23e2752a7afb..a90e5fe84ad5 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts @@ -15,7 +15,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Requires that function parameters are typed as readonly to prevent accidental mutation of inputs', + 'Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-readonly.ts b/packages/eslint-plugin/src/rules/prefer-readonly.ts index 816a79371fbe..b9d9b76803b4 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly.ts @@ -23,7 +23,7 @@ export default util.createRule({ meta: { docs: { description: - "Requires that private members are marked as `readonly` if they're never modified outside of the constructor", + "Require private members to be marked as `readonly` if they're never modified outside of the constructor", recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts index d034095a6f80..d4f6501a89d3 100644 --- a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts +++ b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts @@ -28,7 +28,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Prefer using type parameter when calling `Array#reduce` instead of casting', + 'Enforce using type parameter when calling `Array#reduce` instead of casting', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts index 07c98a69240a..3d5fca34627e 100644 --- a/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts +++ b/packages/eslint-plugin/src/rules/prefer-regexp-exec.ts @@ -25,7 +25,7 @@ export default createRule({ fixable: 'code', docs: { description: - 'Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided', + 'Enforce `RegExp#exec` over `String#match` if no global flag is provided', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index 8d95b9a5f2e8..c658bce3dd18 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -22,7 +22,7 @@ export default createRule({ type: 'suggestion', docs: { description: - 'Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings', + 'Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings', recommended: 'strict', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts b/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts index 371b063d1d6a..3be8b5159f1f 100644 --- a/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts +++ b/packages/eslint-plugin/src/rules/prefer-ts-expect-error.ts @@ -9,7 +9,7 @@ export default util.createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Recommends using `@ts-expect-error` over `@ts-ignore`', + description: 'Enforce using `@ts-expect-error` over `@ts-ignore`', recommended: 'strict', }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/promise-function-async.ts b/packages/eslint-plugin/src/rules/promise-function-async.ts index bf49764a6818..b1ade7bf01b7 100644 --- a/packages/eslint-plugin/src/rules/promise-function-async.ts +++ b/packages/eslint-plugin/src/rules/promise-function-async.ts @@ -25,7 +25,7 @@ export default util.createRule({ fixable: 'code', docs: { description: - 'Requires any function or method that returns a Promise to be marked async', + 'Require any function or method that returns a Promise to be marked async', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index ae9ea48a4fac..5354c87afa64 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -20,7 +20,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'Requires `Array#sort` calls to always provide a `compareFunction`', + 'Require `Array#sort` calls to always provide a `compareFunction`', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 6d2052b6be7e..3884dec24dd0 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -21,7 +21,7 @@ export default util.createRule({ type: 'problem', docs: { description: - 'When adding two variables, operands must both be of type number or of type string', + 'Require both operands of addition to have type `number` or `string`', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts index b4d70ab53502..0140c3dc0d47 100644 --- a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts +++ b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts @@ -19,7 +19,8 @@ export default util.createRule({ meta: { type: 'problem', docs: { - description: 'Enforce template literal expressions to be of string type', + description: + 'Enforce template literal expressions to be of `string` type', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/return-await.ts b/packages/eslint-plugin/src/rules/return-await.ts index d388d84c4809..fbb78708bd44 100644 --- a/packages/eslint-plugin/src/rules/return-await.ts +++ b/packages/eslint-plugin/src/rules/return-await.ts @@ -19,7 +19,7 @@ export default util.createRule({ name: 'return-await', meta: { docs: { - description: 'Enforces consistent returning of awaited values', + description: 'Enforce consistent returning of awaited values', recommended: false, requiresTypeChecking: true, extendsBaseRule: 'no-return-await', diff --git a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts index fe7f698949c7..f96c4677506d 100644 --- a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts +++ b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts @@ -106,7 +106,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Enforces that members of a type union/intersection are sorted alphabetically', + 'Enforce members of a type union/intersection to be sorted alphabetically', recommended: false, }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/space-before-blocks.ts b/packages/eslint-plugin/src/rules/space-before-blocks.ts index 5bf827df96c3..f4d4d28ef6a3 100644 --- a/packages/eslint-plugin/src/rules/space-before-blocks.ts +++ b/packages/eslint-plugin/src/rules/space-before-blocks.ts @@ -12,7 +12,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: 'Enforces consistent spacing before blocks', + description: 'Enforce consistent spacing before blocks', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index 6c6995db02f6..2b34036b832a 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -19,7 +19,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: 'Enforces consistent spacing before function parenthesis', + description: 'Enforce consistent spacing before function parenthesis', recommended: false, extendsBaseRule: true, }, diff --git a/packages/eslint-plugin/src/rules/space-infix-ops.ts b/packages/eslint-plugin/src/rules/space-infix-ops.ts index ff6e15ac3400..cd2be0409bc5 100644 --- a/packages/eslint-plugin/src/rules/space-infix-ops.ts +++ b/packages/eslint-plugin/src/rules/space-infix-ops.ts @@ -14,8 +14,7 @@ export default util.createRule({ meta: { type: 'layout', docs: { - description: - 'This rule is aimed at ensuring there are spaces around infix operators.', + description: 'Require spacing around infix operators', recommended: false, extendsBaseRule: true, }, @@ -69,7 +68,10 @@ export default util.createRule({ }; function isSpaceChar(token: TSESTree.Token): boolean { - return token.type === AST_TOKEN_TYPES.Punctuator && token.value === '='; + return ( + token.type === AST_TOKEN_TYPES.Punctuator && + /^[=|?|:]$/.test(token.value) + ); } function checkAndReportAssignmentSpace( @@ -180,6 +182,21 @@ export default util.createRule({ checkAndReportAssignmentSpace(node, leftNode, rightNode); } + function checkForTypeConditional(node: TSESTree.TSConditionalType): void { + const extendsTypeNode = sourceCode.getTokenByRangeStart( + node.extendsType.range[0], + )!; + const trueTypeNode = sourceCode.getTokenByRangeStart( + node.trueType.range[0], + )!; + const falseTypeNode = sourceCode.getTokenByRangeStart( + node.falseType.range[0], + ); + + checkAndReportAssignmentSpace(node, extendsTypeNode, trueTypeNode); + checkAndReportAssignmentSpace(node, trueTypeNode, falseTypeNode); + } + return { ...rules, TSEnumMember: checkForEnumAssignmentSpace, @@ -187,6 +204,7 @@ export default util.createRule({ TSTypeAliasDeclaration: checkForTypeAliasAssignment, TSUnionType: checkForTypeAnnotationSpace, TSIntersectionType: checkForTypeAnnotationSpace, + TSConditionalType: checkForTypeConditional, }; }, }); diff --git a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts index 0a91b2fca950..5493e84d271c 100644 --- a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts +++ b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts @@ -51,7 +51,7 @@ export default util.createRule({ fixable: 'code', hasSuggestions: true, docs: { - description: 'Restricts the types allowed in boolean expressions', + description: 'Disallow certain types in boolean expressions', recommended: false, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts index 49ed2d905b69..bb11c245722c 100644 --- a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts +++ b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts @@ -15,7 +15,8 @@ export default createRule({ meta: { type: 'suggestion', docs: { - description: 'Exhaustiveness checking in switch with union type', + description: + 'Require switch-case statements to be exhaustive with union type', recommended: false, suggestion: true, requiresTypeChecking: true, diff --git a/packages/eslint-plugin/src/rules/triple-slash-reference.ts b/packages/eslint-plugin/src/rules/triple-slash-reference.ts index cf769237fff9..89af33735845 100644 --- a/packages/eslint-plugin/src/rules/triple-slash-reference.ts +++ b/packages/eslint-plugin/src/rules/triple-slash-reference.ts @@ -20,7 +20,7 @@ export default util.createRule({ type: 'suggestion', docs: { description: - 'Sets preference level for triple slash directives versus ES6-style import declarations', + 'Disallow certain triple slash directives in favor of ES6-style import declarations', recommended: 'error', }, messages: { diff --git a/packages/eslint-plugin/src/rules/typedef.ts b/packages/eslint-plugin/src/rules/typedef.ts index 4bd69d9a4791..a995fe41b37f 100644 --- a/packages/eslint-plugin/src/rules/typedef.ts +++ b/packages/eslint-plugin/src/rules/typedef.ts @@ -20,7 +20,7 @@ export default util.createRule<[Options], MessageIds>({ name: 'typedef', meta: { docs: { - description: 'Requires type annotations to exist', + description: 'Require type annotations in certain places', recommended: false, }, messages: { diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index 2dd6aafaebf1..2c62881e81b1 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -126,7 +126,7 @@ export default util.createRule({ meta: { docs: { description: - 'Enforces unbound methods are called with their expected scope', + 'Enforce unbound methods are called with their expected scope', recommended: 'error', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 2c88f48a2bd9..dc1f683ee35b 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -64,7 +64,7 @@ export default util.createRule({ meta: { docs: { description: - 'Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter', + 'Disallow two overloads that could be unified into one with a union or an optional/rest parameter', // too opinionated to be recommended recommended: 'strict', }, diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index 8479feb728dd..2a9046854a36 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -4,12 +4,24 @@ import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils'; import { requiresQuoting } from '@typescript-eslint/type-utils'; +import * as ts from 'typescript'; +const DEFINITION_EXTENSIONS = [ + ts.Extension.Dts, + ts.Extension.Dcts, + ts.Extension.Dmts, +] as const; /** * Check if the context file name is *.d.ts or *.d.tsx */ function isDefinitionFile(fileName: string): boolean { - return /\.d\.tsx?$/i.test(fileName || ''); + const lowerFileName = fileName.toLowerCase(); + for (const definitionExt of DEFINITION_EXTENSIONS) { + if (lowerFileName.endsWith(definitionExt)) { + return true; + } + } + return false; } /** diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index ca7cc5fbd8f4..c3564a566743 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -10,8 +10,10 @@ import { titleCase } from 'title-case'; const docsRoot = path.resolve(__dirname, '../docs/rules'); const rulesData = Object.entries(rules); -function createRuleLink(ruleName: string): string { - return `[\`@typescript-eslint/${ruleName}\`](./docs/rules/${ruleName}.md)`; +function createRuleLink(ruleName: string, readmePath: string): string { + return `[\`@typescript-eslint/${ruleName}\`](${ + readmePath.includes('docs/rules') ? '.' : './docs/rules' + }/${ruleName}.md)`; } function parseMarkdownFile(filePath: string): marked.TokensList { @@ -23,11 +25,11 @@ function parseMarkdownFile(filePath: string): marked.TokensList { }); } -function parseReadme(): { +function parseReadme(readmePath: string): { base: marked.Tokens.Table; extension: marked.Tokens.Table; } { - const readme = parseMarkdownFile(path.resolve(__dirname, '../README.md')); + const readme = parseMarkdownFile(readmePath); // find the table const rulesTables = readme.filter( @@ -113,7 +115,10 @@ describe('Validating rule docs', () => { // Rule title does not match the rule metadata. expect(tokens[1]).toMatchObject({ type: 'paragraph', - text: `${rule.meta.docs?.description}.`, + text: `${rule.meta.docs?.description.replace( + /(? { } }); -describe('Validating README.md', () => { - const rulesTables = parseReadme(); +describe.each([ + path.join(__dirname, '../README.md'), + path.join(__dirname, '../docs/rules/README.md'), +])('%s', readmePath => { + const rulesTables = parseReadme(readmePath); const notDeprecated = rulesData.filter(([, rule]) => !rule.meta.deprecated); const baseRules = notDeprecated.filter( ([, rule]) => !rule.meta.docs?.extendsBaseRule, @@ -250,7 +258,7 @@ describe('Validating README.md', () => { const baseRuleNames = baseRules .map(([ruleName]) => ruleName) .sort() - .map(createRuleLink); + .map(ruleName => createRuleLink(ruleName, readmePath)); expect(rulesTables.base.rows.map(row => row[0].text)).toStrictEqual( baseRuleNames, @@ -260,7 +268,7 @@ describe('Validating README.md', () => { const extensionRuleNames = extensionRules .map(([ruleName]) => ruleName) .sort() - .map(createRuleLink); + .map(ruleName => createRuleLink(ruleName, readmePath)); expect(rulesTables.extension.rows.map(row => row[0].text)).toStrictEqual( extensionRuleNames, @@ -283,7 +291,7 @@ describe('Validating README.md', () => { } it('Link column should be correct', () => { - expect(ruleRow[0]).toBe(createRuleLink(ruleName)); + expect(ruleRow[0]).toBe(createRuleLink(ruleName, readmePath)); }); it('Description column should be correct', () => { diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts index b9d10b005b6f..3843df63ef41 100644 --- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts @@ -34,6 +34,17 @@ ruleTester.run('ts-expect-error', rule, { }, ], }, + { + code: '// @ts-expect-error: TS1234 because xyz', + options: [ + { + 'ts-expect-error': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 10, + }, + ], + }, ], invalid: [ { @@ -162,6 +173,61 @@ if (false) { }, ], }, + { + code: '// @ts-expect-error: TS1234 because xyz', + options: [ + { + 'ts-expect-error': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 25, + }, + ], + errors: [ + { + data: { directive: 'expect-error', minimumDescriptionLength: 25 }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-expect-error: TS1234', + options: [ + { + 'ts-expect-error': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'expect-error', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, + { + code: noFormat`// @ts-expect-error : TS1234 because xyz`, + options: [ + { + 'ts-expect-error': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'expect-error', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -189,6 +255,17 @@ ruleTester.run('ts-ignore', rule, { }, ], }, + { + code: '// @ts-ignore: TS1234 because xyz', + options: [ + { + 'ts-ignore': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 10, + }, + ], + }, ], invalid: [ { @@ -328,6 +405,61 @@ if (false) { }, ], }, + { + code: '// @ts-ignore: TS1234 because xyz', + options: [ + { + 'ts-ignore': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 25, + }, + ], + errors: [ + { + data: { directive: 'ignore', minimumDescriptionLength: 25 }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-ignore: TS1234', + options: [ + { + 'ts-ignore': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'ignore', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, + { + code: noFormat`// @ts-ignore : TS1234 because xyz`, + options: [ + { + 'ts-ignore': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'ignore', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -355,6 +487,17 @@ ruleTester.run('ts-nocheck', rule, { }, ], }, + { + code: '// @ts-nocheck: TS1234 because xyz', + options: [ + { + 'ts-nocheck': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 10, + }, + ], + }, ], invalid: [ { @@ -470,6 +613,61 @@ if (false) { }, ], }, + { + code: '// @ts-nocheck: TS1234 because xyz', + options: [ + { + 'ts-nocheck': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 25, + }, + ], + errors: [ + { + data: { directive: 'nocheck', minimumDescriptionLength: 25 }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-nocheck: TS1234', + options: [ + { + 'ts-nocheck': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'nocheck', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, + { + code: noFormat`// @ts-nocheck : TS1234 because xyz`, + options: [ + { + 'ts-nocheck': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'nocheck', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, ], }); @@ -491,6 +689,17 @@ ruleTester.run('ts-check', rule, { { 'ts-check': 'allow-with-description', minimumDescriptionLength: 3 }, ], }, + { + code: '// @ts-check: TS1234 because xyz', + options: [ + { + 'ts-check': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 10, + }, + ], + }, ], invalid: [ { @@ -588,16 +797,71 @@ if (false) { ], }, { - code: '// @ts-ignore', - options: [{ 'ts-ignore': 'allow-with-description' }], + code: '// @ts-check', + options: [{ 'ts-check': 'allow-with-description' }], errors: [ { - data: { directive: 'ignore', minimumDescriptionLength: 3 }, + data: { directive: 'check', minimumDescriptionLength: 3 }, messageId: 'tsDirectiveCommentRequiresDescription', line: 1, column: 1, }, ], }, + { + code: '// @ts-check: TS1234 because xyz', + options: [ + { + 'ts-check': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + minimumDescriptionLength: 25, + }, + ], + errors: [ + { + data: { directive: 'check', minimumDescriptionLength: 25 }, + messageId: 'tsDirectiveCommentRequiresDescription', + line: 1, + column: 1, + }, + ], + }, + { + code: '// @ts-check: TS1234', + options: [ + { + 'ts-check': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'check', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, + { + code: noFormat`// @ts-check : TS1234 because xyz`, + options: [ + { + 'ts-check': { + descriptionFormat: '^: TS\\d+ because .+$', + }, + }, + ], + errors: [ + { + data: { directive: 'check', format: '^: TS\\d+ because .+$' }, + messageId: 'tsDirectiveCommentDescriptionNotMatchPattern', + line: 1, + column: 1, + }, + ], + }, ], }); diff --git a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts index 518b7c1d6b5d..1551cfbfcf37 100644 --- a/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-misused-promises.test.ts @@ -316,6 +316,63 @@ const _ = {}} />; `, filename: 'react.tsx', }, + ` +console.log({ ...(await Promise.resolve({ key: 42 })) }); + `, + ` +const getData = () => Promise.resolve({ key: 42 }); + +console.log({ + someData: 42, + ...(await getData()), +}); + `, + ` +declare const condition: boolean; + +console.log({ ...(condition && (await Promise.resolve({ key: 42 }))) }); +console.log({ ...(condition || (await Promise.resolve({ key: 42 }))) }); +console.log({ ...(condition ? {} : await Promise.resolve({ key: 42 })) }); +console.log({ ...(condition ? await Promise.resolve({ key: 42 }) : {}) }); + `, + ` +console.log([...(await Promise.resolve(42))]); + `, + { + code: ` +console.log({ ...Promise.resolve({ key: 42 }) }); + `, + options: [{ checksSpreads: false }], + }, + { + code: ` +const getData = () => Promise.resolve({ key: 42 }); + +console.log({ + someData: 42, + ...getData(), +}); + `, + options: [{ checksSpreads: false }], + }, + { + code: ` +declare const condition: boolean; + +console.log({ ...(condition && Promise.resolve({ key: 42 })) }); +console.log({ ...(condition || Promise.resolve({ key: 42 })) }); +console.log({ ...(condition ? {} : Promise.resolve({ key: 42 })) }); +console.log({ ...(condition ? Promise.resolve({ key: 42 }) : {}) }); + `, + options: [{ checksSpreads: false }], + }, + { + code: ` +// This is invalid Typescript, but it shouldn't trigger this linter specifically +console.log([...Promise.resolve(42)]); + `, + options: [{ checksSpreads: false }], + }, ], invalid: [ @@ -870,5 +927,48 @@ it('', async () => {}); }, ], }, + { + code: ` +console.log({ ...Promise.resolve({ key: 42 }) }); + `, + errors: [ + { + line: 2, + messageId: 'spread', + }, + ], + }, + { + code: ` +const getData = () => Promise.resolve({ key: 42 }); + +console.log({ + someData: 42, + ...getData(), +}); + `, + errors: [ + { + line: 6, + messageId: 'spread', + }, + ], + }, + { + code: ` +declare const condition: boolean; + +console.log({ ...(condition && Promise.resolve({ key: 42 })) }); +console.log({ ...(condition || Promise.resolve({ key: 42 })) }); +console.log({ ...(condition ? {} : Promise.resolve({ key: 42 })) }); +console.log({ ...(condition ? Promise.resolve({ key: 42 }) : {}) }); + `, + errors: [ + { line: 4, messageId: 'spread' }, + { line: 5, messageId: 'spread' }, + { line: 6, messageId: 'spread' }, + { line: 7, messageId: 'spread' }, + ], + }, ], }); diff --git a/packages/eslint-plugin/tests/rules/no-type-alias.test.ts b/packages/eslint-plugin/tests/rules/no-type-alias.test.ts index f0da2160b632..6a307454f512 100644 --- a/packages/eslint-plugin/tests/rules/no-type-alias.test.ts +++ b/packages/eslint-plugin/tests/rules/no-type-alias.test.ts @@ -131,6 +131,66 @@ ruleTester.run('no-type-alias', rule, { code: 'type Foo = 1 | (2 & 3);', options: [{ allowAliases: 'in-unions-and-intersections' }], }, + { + code: 'type Foo = `a-${number}`;', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}`;', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}`;', + options: [{ allowAliases: 'in-unions-and-intersections' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}`;', + options: [{ allowAliases: 'in-unions' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;', + options: [{ allowAliases: 'in-unions-and-intersections' }], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}` | `c-${number}`;', + options: [{ allowAliases: 'in-unions' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}`;', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}`;', + options: [{ allowAliases: 'in-unions-and-intersections' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}`;', + options: [{ allowAliases: 'in-intersections' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;', + options: [{ allowAliases: 'in-unions-and-intersections' }], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}` & `c-${number}`;', + options: [{ allowAliases: 'in-intersections' }], + }, + { + code: 'type Foo = `a-${number}` | (`b-${number}` & `c-${number}`);', + options: [{ allowAliases: 'always' }], + }, + { + code: 'type Foo = `a-${number}` | (`b-${number}` & `c-${number}`);', + options: [{ allowAliases: 'in-unions-and-intersections' }], + }, { code: 'type Foo = true;', options: [{ allowAliases: 'always' }], @@ -3340,5 +3400,66 @@ type Foo = { }, ], }, + { + code: 'type Foo = `foo-${number}`;', + errors: [ + { + messageId: 'noTypeAlias', + data: { + alias: 'aliases', + }, + line: 1, + column: 12, + }, + ], + }, + { + code: 'type Foo = `a-${number}` | `b-${number}`;', + options: [{ allowAliases: 'never' }], + errors: [ + { + messageId: 'noCompositionAlias', + data: { + typeName: 'Aliases', + compositionType: 'union', + }, + line: 1, + column: 12, + }, + { + messageId: 'noCompositionAlias', + data: { + typeName: 'Aliases', + compositionType: 'union', + }, + line: 1, + column: 28, + }, + ], + }, + { + code: 'type Foo = `a-${number}` & `b-${number}`;', + options: [{ allowAliases: 'never' }], + errors: [ + { + messageId: 'noCompositionAlias', + data: { + typeName: 'Aliases', + compositionType: 'intersection', + }, + line: 1, + column: 12, + }, + { + messageId: 'noCompositionAlias', + data: { + typeName: 'Aliases', + compositionType: 'intersection', + }, + line: 1, + column: 28, + }, + ], + }, ], }); diff --git a/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts b/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts index 72f71d00358b..26e623231671 100644 --- a/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts +++ b/packages/eslint-plugin/tests/rules/space-infix-ops.test.ts @@ -977,6 +977,116 @@ ruleTester.run('space-infix-ops', rule, { }, ], }, + { + code: ` + type Test = T extends boolean?true:false + `, + output: ` + type Test = T extends boolean ? true : false + `, + errors: [ + { + messageId: 'missingSpace', + column: 41, + line: 2, + }, + { + messageId: 'missingSpace', + column: 46, + line: 2, + }, + ], + }, + { + code: ` + type Test = T extends boolean? true :false + `, + output: ` + type Test = T extends boolean ? true : false + `, + errors: [ + { + messageId: 'missingSpace', + column: 41, + line: 2, + }, + { + messageId: 'missingSpace', + column: 48, + line: 2, + }, + ], + }, + { + code: ` + type Test = T extends boolean? + true :false + `, + output: ` + type Test = T extends boolean ? + true : false + `, + errors: [ + { + messageId: 'missingSpace', + column: 41, + line: 2, + }, + { + messageId: 'missingSpace', + column: 16, + line: 3, + }, + ], + }, + { + code: ` + type Test = T extends boolean? + true + :false + `, + output: ` + type Test = T extends boolean ? + true + : false + `, + errors: [ + { + messageId: 'missingSpace', + column: 41, + line: 2, + }, + { + messageId: 'missingSpace', + column: 11, + line: 4, + }, + ], + }, + { + code: ` + type Test = T extends boolean + ?true: + false + `, + output: ` + type Test = T extends boolean + ? true : + false + `, + errors: [ + { + messageId: 'missingSpace', + column: 11, + line: 3, + }, + { + messageId: 'missingSpace', + column: 16, + line: 3, + }, + ], + }, { code: ` interface Test { diff --git a/packages/eslint-plugin/tests/util.test.ts b/packages/eslint-plugin/tests/util.test.ts index 9714ab5718c4..a2f742870779 100644 --- a/packages/eslint-plugin/tests/util.test.ts +++ b/packages/eslint-plugin/tests/util.test.ts @@ -1,7 +1,7 @@ import * as util from '../src/util'; describe('isDefinitionFile', () => { - it('returns false for non-definition files', () => { + describe('returns false for non-definition files', () => { const invalid = [ 'test.js', 'test.jsx', @@ -15,18 +15,25 @@ describe('isDefinitionFile', () => { 'test.tsx', 'test.TS', 'test.TSX', + // yes, it's not a definition file if it's a `.d.tsx`! + 'test.d.tsx', + 'test.D.TSX', ]; invalid.forEach(f => { - expect(util.isDefinitionFile(f)).toBe(false); + it(f, () => { + expect(util.isDefinitionFile(f)).toBe(false); + }); }); }); - it('returns true for definition files', () => { - const valid = ['test.d.ts', 'test.d.tsx', 'test.D.TS', 'test.D.TSX']; + describe('returns true for definition files', () => { + const valid = ['test.d.ts', 'test.D.TS']; valid.forEach(f => { - expect(util.isDefinitionFile(f)).toBe(true); + it(f, () => { + expect(util.isDefinitionFile(f)).toBe(true); + }); }); }); }); diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index feed203c699a..c5fa159a2269 100644 --- a/packages/experimental-utils/CHANGELOG.md +++ b/packages/experimental-utils/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/experimental-utils diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index beaad1f279d6..db82d23cc893 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "5.26.0", + "version": "5.27.0", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -33,12 +33,12 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/utils": "5.26.0" + "@typescript-eslint/utils": "5.27.0" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index d832453d454b..ef72bc8b89c4 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Bug Fixes + +* **types:** remove leftovers from removal of useJSXTextNode ([#5091](https://github.com/typescript-eslint/typescript-eslint/issues/5091)) ([f9c3647](https://github.com/typescript-eslint/typescript-eslint/commit/f9c3647cb637c8d1ee461b471da9d817ccbde77c)) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/parser diff --git a/packages/parser/README.md b/packages/parser/README.md index 81df05194977..018935b2ca9f 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -78,16 +78,19 @@ Default `false`. Enable parsing JSX when `true`. More details can be found [here](https://www.typescriptlang.org/docs/handbook/jsx.html). -**NOTE:** this setting does not affect known file types (`.js`, `.jsx`, `.ts`, `.tsx`, `.json`) because the TypeScript compiler has its own internal handling for known file extensions. The exact behavior is as follows: +**NOTE:** this setting does not affect known file types (`.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.mts`, `.cts`, `.tsx`, `.json`) because the TypeScript compiler has its own internal handling for known file extensions. -- if `parserOptions.project` is _not_ provided: - - `.js`, `.jsx`, `.tsx` files are parsed as if this is true. - - `.ts` files are parsed as if this is false. - - unknown extensions (`.md`, `.vue`) will respect this setting. -- if `parserOptions.project` is provided (i.e. you are using rules with type information): - - `.js`, `.jsx`, `.tsx` files are parsed as if this is true. - - `.ts` files are parsed as if this is false. - - "unknown" extensions (`.md`, `.vue`) **are parsed as if this is false**. + + +The exact behavior is as follows: + +- `.js`, `.mjs`, `.cjs`, `.jsx`, `.tsx` files are always parsed as if this is `true`. +- `.ts`, `.mts`, `.cts` files are always parsed as if this is `false`. +- For "unknown" extensions (`.md`, `.vue`): + - If `parserOptions.project` is _not_ provided: + - The setting will be respected. + - If `parserOptions.project` is provided (i.e. you are using rules with type information): + - **always parsed as if this is `false`** ### `parserOptions.ecmaFeatures.globalReturn` @@ -203,7 +206,8 @@ For example, by default it will ensure that a glob like `./**/tsconfig.json` wil Default `undefined`. This option allows you to provide one or more additional file extensions which should be considered in the TypeScript Program compilation. -The default extensions are `.ts`, `.tsx`, `.js`, and `.jsx`. Add extensions starting with `.`, followed by the file extension. E.g. for a `.vue` file use `"extraFileExtensions": [".vue"]`. +The default extensions are `['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx']`. +Add extensions starting with `.`, followed by the file extension. E.g. for a `.vue` file use `"extraFileExtensions": [".vue"]`. ### `parserOptions.warnOnUnsupportedTypeScriptVersion` diff --git a/packages/parser/package.json b/packages/parser/package.json index fcb40066bf43..7d9e0297c1cf 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "5.26.0", + "version": "5.27.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -35,8 +35,8 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, @@ -44,9 +44,9 @@ "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "dependencies": { - "@typescript-eslint/scope-manager": "5.26.0", - "@typescript-eslint/types": "5.26.0", - "@typescript-eslint/typescript-estree": "5.26.0", + "@typescript-eslint/scope-manager": "5.27.0", + "@typescript-eslint/types": "5.27.0", + "@typescript-eslint/typescript-estree": "5.27.0", "debug": "^4.3.4" }, "devDependencies": { diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 365bff6648f8..94689968cac5 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -36,7 +36,7 @@ function validateBoolean( return value; } -const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.ts$/; +const LIB_FILENAME_REGEX = /lib\.(.+)\.d\.[cm]?ts$/; function getLib(compilerOptions: CompilerOptions): Lib[] { if (compilerOptions.lib) { return compilerOptions.lib.reduce((acc, lib) => { @@ -98,7 +98,6 @@ function parseForESLint( const parserOptions: TSESTreeOptions = {}; Object.assign(parserOptions, options, { - useJSXTextNode: validateBoolean(options.useJSXTextNode, true), jsx: validateBoolean(options.ecmaFeatures.jsx), }); const analyzeOptions: AnalyzeOptions = { @@ -110,13 +109,6 @@ function parseForESLint( sourceType: options.sourceType, }; - if (typeof options.filePath === 'string') { - const tsx = options.filePath.endsWith('.tsx'); - if (tsx || options.filePath.endsWith('.ts')) { - parserOptions.jsx = tsx; - } - } - /** * Allow the user to suppress the warning from typescript-estree if they are using an unsupported * version of TypeScript diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index ba319185b1fa..096905b23aaf 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -40,7 +40,6 @@ describe('parser', () => { // ts-estree specific filePath: 'isolated-file.src.ts', project: 'tsconfig.json', - useJSXTextNode: false, errorOnUnknownASTType: false, errorOnTypeScriptSyntacticAndSemanticIssues: false, tsconfigRootDir: 'tests/fixtures/services', @@ -62,7 +61,6 @@ describe('parser', () => { ecmaFeatures: {}, jsx: false, sourceType: 'script', - useJSXTextNode: true, warnOnUnsupportedTypeScriptVersion: true, }); spy.mockClear(); @@ -71,7 +69,6 @@ describe('parser', () => { ecmaFeatures: {}, jsx: false, sourceType: 'script', - useJSXTextNode: true, loggerFn: false, warnOnUnsupportedTypeScriptVersion: false, }); @@ -98,7 +95,6 @@ describe('parser', () => { // ts-estree specific filePath: 'isolated-file.src.ts', project: 'tsconfig.json', - useJSXTextNode: false, errorOnUnknownASTType: false, errorOnTypeScriptSyntacticAndSemanticIssues: false, tsconfigRootDir: 'tests/fixtures/services', diff --git a/packages/scope-manager/CHANGELOG.md b/packages/scope-manager/CHANGELOG.md index 96e2f4e18e49..06dddef47f6c 100644 --- a/packages/scope-manager/CHANGELOG.md +++ b/packages/scope-manager/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/scope-manager diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index e45e825f30a0..4475a4c9c121 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/scope-manager", - "version": "5.26.0", + "version": "5.27.0", "description": "TypeScript scope analyser for ESLint", "keywords": [ "eslint", @@ -31,19 +31,19 @@ "build": "cd ../../ && nx build @typescript-eslint/scope-manager", "clean": "cd ../../ && nx clean @typescript-eslint/scope-manager", "clean-fixtures": "cd ../../ && nx clean-fixtures @typescript-eslint/scope-manager", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", "generate:lib": "cd ../../ && nx generate-lib @typescript-eslint/scope-manager", "lint": "cd ../../ && nx lint @typescript-eslint/scope-manager", "test": "cd ../../ && nx test @typescript-eslint/scope-manager --code-coverage", "typecheck": "cd ../../ && nx typecheck @typescript-eslint/scope-manager" }, "dependencies": { - "@typescript-eslint/types": "5.26.0", - "@typescript-eslint/visitor-keys": "5.26.0" + "@typescript-eslint/types": "5.27.0", + "@typescript-eslint/visitor-keys": "5.27.0" }, "devDependencies": { "@types/glob": "*", - "@typescript-eslint/typescript-estree": "5.26.0", + "@typescript-eslint/typescript-estree": "5.27.0", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 2b4c428a0599..a34869891da5 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [TS4.7] support type parameters for `typeof` ([#5067](https://github.com/typescript-eslint/typescript-eslint/issues/5067)) ([836de79](https://github.com/typescript-eslint/typescript-eslint/commit/836de79e8d1bff43149168cc913a4c2b60e79bf6)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/packages/shared-fixtures/fixtures/typescript/types/typeof-with-type-parameters.src.ts b/packages/shared-fixtures/fixtures/typescript/types/typeof-with-type-parameters.src.ts new file mode 100644 index 000000000000..7287d407d29d --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/types/typeof-with-type-parameters.src.ts @@ -0,0 +1 @@ +let x: typeof y.z; diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json index d566b750d8a3..909d39033a40 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,5 +1,5 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "5.26.0", + "version": "5.27.0", "private": true } diff --git a/packages/type-utils/CHANGELOG.md b/packages/type-utils/CHANGELOG.md index a223df579620..e9238660efe5 100644 --- a/packages/type-utils/CHANGELOG.md +++ b/packages/type-utils/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/type-utils diff --git a/packages/type-utils/package.json b/packages/type-utils/package.json index bd660ad19901..a2854d3d34fe 100644 --- a/packages/type-utils/package.json +++ b/packages/type-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/type-utils", - "version": "5.26.0", + "version": "5.27.0", "description": "Type utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -33,18 +33,18 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/utils": "5.26.0", + "@typescript-eslint/utils": "5.27.0", "debug": "^4.3.4", "tsutils": "^3.21.0" }, "devDependencies": { - "@typescript-eslint/parser": "5.26.0", + "@typescript-eslint/parser": "5.27.0", "typescript": "*" }, "peerDependencies": { diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index b8a99c2555ed..73678dd49599 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Bug Fixes + +* **types:** remove leftovers from removal of useJSXTextNode ([#5091](https://github.com/typescript-eslint/typescript-eslint/issues/5091)) ([f9c3647](https://github.com/typescript-eslint/typescript-eslint/commit/f9c3647cb637c8d1ee461b471da9d817ccbde77c)) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/types diff --git a/packages/types/package.json b/packages/types/package.json index e1b20f66ede5..ca8fb4099b4f 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/types", - "version": "5.26.0", + "version": "5.27.0", "description": "Types for the TypeScript-ESTree AST spec", "keywords": [ "eslint", @@ -33,9 +33,9 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", "generate:lib": "../../node_modules/.bin/ts-node --files --transpile-only ../scope-manager/tools/generate-lib.ts", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "lint": "eslint . --ignore-path='../../.eslintignore'", "typecheck": "tsc -p tsconfig.json --noEmit" }, "nx": { diff --git a/packages/types/src/parser-options.ts b/packages/types/src/parser-options.ts index c54d38c73b9f..bb5101768e03 100644 --- a/packages/types/src/parser-options.ts +++ b/packages/types/src/parser-options.ts @@ -56,7 +56,6 @@ interface ParserOptions { sourceType?: SourceType; tokens?: boolean; tsconfigRootDir?: string; - useJSXTextNode?: boolean; warnOnUnsupportedTypeScriptVersion?: boolean; moduleResolver?: string; } diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index b1bd82a8d33d..13bc5a35f5c7 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,24 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Bug Fixes + +* **types:** remove leftovers from removal of useJSXTextNode ([#5091](https://github.com/typescript-eslint/typescript-eslint/issues/5091)) ([f9c3647](https://github.com/typescript-eslint/typescript-eslint/commit/f9c3647cb637c8d1ee461b471da9d817ccbde77c)) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) +* [TS4.7] support type parameters for `typeof` ([#5067](https://github.com/typescript-eslint/typescript-eslint/issues/5067)) ([836de79](https://github.com/typescript-eslint/typescript-eslint/commit/836de79e8d1bff43149168cc913a4c2b60e79bf6)) +* bump dependency ranges to TypeScript 4.7 ([#5082](https://github.com/typescript-eslint/typescript-eslint/issues/5082)) ([c4310b1](https://github.com/typescript-eslint/typescript-eslint/commit/c4310b1aac35c7d31b826f0602eca6a5900a09ee)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/packages/typescript-estree/README.md b/packages/typescript-estree/README.md index f235f3dcf212..02946daa80df 100644 --- a/packages/typescript-estree/README.md +++ b/packages/typescript-estree/README.md @@ -69,7 +69,7 @@ interface ParseOptions { * Enable parsing of JSX. * For more details, see https://www.typescriptlang.org/docs/handbook/jsx.html * - * NOTE: this setting does not effect known file types (.js, .jsx, .ts, .tsx, .json) because the + * NOTE: this setting does not effect known file types (.js, .cjs, .mjs, .jsx, .ts, .mts, .cts, .tsx, .json) because the * TypeScript compiler has its own internal handling for known file extensions. * * For the exact behavior, see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser#parseroptionsecmafeaturesjsx diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 24366e8f398f..8c8fc42c13f0 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "5.26.0", + "version": "5.27.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -35,14 +35,14 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "5.26.0", - "@typescript-eslint/visitor-keys": "5.26.0", + "@typescript-eslint/types": "5.27.0", + "@typescript-eslint/visitor-keys": "5.27.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -58,7 +58,7 @@ "@types/is-glob": "*", "@types/semver": "*", "@types/tmp": "*", - "@typescript-eslint/shared-fixtures": "5.26.0", + "@typescript-eslint/shared-fixtures": "5.27.0", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 9e5764296903..864f85d2cd2b 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -2429,6 +2429,9 @@ export class Converter { return this.createNode(node, { type: AST_NODE_TYPES.TSTypeQuery, exprName: this.convertType(node.exprName), + typeParameters: + node.typeArguments && + this.convertTypeArgumentsToTypeParameters(node.typeArguments, node), }); } diff --git a/packages/typescript-estree/src/create-program/createIsolatedProgram.ts b/packages/typescript-estree/src/create-program/createIsolatedProgram.ts index 70169c66891b..c4392941bb67 100644 --- a/packages/typescript-estree/src/create-program/createIsolatedProgram.ts +++ b/packages/typescript-estree/src/create-program/createIsolatedProgram.ts @@ -1,11 +1,8 @@ import debug from 'debug'; import * as ts from 'typescript'; import { Extra } from '../parser-options'; -import { - ASTAndProgram, - createDefaultCompilerOptionsFromExtra, - getScriptKind, -} from './shared'; +import { ASTAndProgram, createDefaultCompilerOptionsFromExtra } from './shared'; +import { getScriptKind } from './getScriptKind'; const log = debug('typescript-eslint:typescript-estree:createIsolatedProgram'); @@ -47,7 +44,7 @@ function createIsolatedProgram(code: string, extra: Extra): ASTAndProgram { code, ts.ScriptTarget.Latest, /* setParentNodes */ true, - getScriptKind(extra, filename), + getScriptKind(extra.filePath, extra.jsx), ); }, readFile() { diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index 69903a5bcafc..4558cc36b55b 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -1,5 +1,6 @@ import debug from 'debug'; import path from 'path'; +import * as ts from 'typescript'; import { getProgramsForProjects } from './createWatchProgram'; import { firstDefined } from '../node-utils'; import { Extra } from '../parser-options'; @@ -7,7 +8,16 @@ import { ASTAndProgram, getAstFromProgram } from './shared'; const log = debug('typescript-eslint:typescript-estree:createProjectProgram'); -const DEFAULT_EXTRA_FILE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx']; +const DEFAULT_EXTRA_FILE_EXTENSIONS = [ + ts.Extension.Ts, + ts.Extension.Tsx, + ts.Extension.Js, + ts.Extension.Jsx, + ts.Extension.Mjs, + ts.Extension.Mts, + ts.Extension.Cjs, + ts.Extension.Cts, +] as readonly string[]; /** * @param code The code of the file being linted diff --git a/packages/typescript-estree/src/create-program/createSourceFile.ts b/packages/typescript-estree/src/create-program/createSourceFile.ts index 70820c1d2172..e3c6acf6dffb 100644 --- a/packages/typescript-estree/src/create-program/createSourceFile.ts +++ b/packages/typescript-estree/src/create-program/createSourceFile.ts @@ -1,7 +1,7 @@ import debug from 'debug'; import * as ts from 'typescript'; import { Extra } from '../parser-options'; -import { getScriptKind } from './shared'; +import { getScriptKind } from './getScriptKind'; const log = debug('typescript-eslint:typescript-estree:createSourceFile'); @@ -17,7 +17,7 @@ function createSourceFile(code: string, extra: Extra): ts.SourceFile { code, ts.ScriptTarget.Latest, /* setParentNodes */ true, - getScriptKind(extra), + getScriptKind(extra.filePath, extra.jsx), ); } diff --git a/packages/typescript-estree/src/create-program/getScriptKind.ts b/packages/typescript-estree/src/create-program/getScriptKind.ts new file mode 100644 index 000000000000..80158f468f7b --- /dev/null +++ b/packages/typescript-estree/src/create-program/getScriptKind.ts @@ -0,0 +1,50 @@ +import path from 'path'; +import * as ts from 'typescript'; + +function getScriptKind(filePath: string, jsx: boolean): ts.ScriptKind { + const extension = path.extname(filePath).toLowerCase(); + // note - we only respect the user's jsx setting for unknown extensions + // this is so that we always match TS's internal script kind logic, preventing + // weird errors due to a mismatch. + // https://github.com/microsoft/TypeScript/blob/da00ba67ed1182ad334f7c713b8254fba174aeba/src/compiler/utilities.ts#L6948-L6968 + switch (extension) { + case ts.Extension.Js: + case ts.Extension.Cjs: + case ts.Extension.Mjs: + return ts.ScriptKind.JS; + + case ts.Extension.Jsx: + return ts.ScriptKind.JSX; + + case ts.Extension.Ts: + case ts.Extension.Cts: + case ts.Extension.Mts: + return ts.ScriptKind.TS; + + case ts.Extension.Tsx: + return ts.ScriptKind.TSX; + + case ts.Extension.Json: + return ts.ScriptKind.JSON; + + default: + // unknown extension, force typescript to ignore the file extension, and respect the user's setting + return jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS; + } +} + +function getLanguageVariant(scriptKind: ts.ScriptKind): ts.LanguageVariant { + // https://github.com/microsoft/TypeScript/blob/d6e483b8dabd8fd37c00954c3f2184bb7f1eb90c/src/compiler/utilities.ts#L6281-L6285 + switch (scriptKind) { + case ts.ScriptKind.TSX: + case ts.ScriptKind.JSX: + case ts.ScriptKind.JS: + case ts.ScriptKind.JSON: + return ts.LanguageVariant.JSX; + + default: + return ts.LanguageVariant.Standard; + } +} + +export { getScriptKind, getLanguageVariant }; diff --git a/packages/typescript-estree/src/create-program/shared.ts b/packages/typescript-estree/src/create-program/shared.ts index 53d6fe9ee4de..770b137f212f 100644 --- a/packages/typescript-estree/src/create-program/shared.ts +++ b/packages/typescript-estree/src/create-program/shared.ts @@ -72,40 +72,21 @@ function canonicalDirname(p: CanonicalPath): CanonicalPath { return path.dirname(p) as CanonicalPath; } -function getScriptKind( - extra: Extra, - filePath: string = extra.filePath, -): ts.ScriptKind { - const extension = path.extname(filePath).toLowerCase(); - // note - we respect the user's extension when it is known we could override it and force it to match their - // jsx setting, but that could create weird situations where we throw parse errors when TSC doesn't - switch (extension) { - case '.ts': - return ts.ScriptKind.TS; - - case '.tsx': - return ts.ScriptKind.TSX; - - case '.js': - return ts.ScriptKind.JS; - - case '.jsx': - return ts.ScriptKind.JSX; - - case '.json': - return ts.ScriptKind.JSON; - - default: - // unknown extension, force typescript to ignore the file extension, and respect the user's setting - return extra.jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS; - } -} - +const DEFINITION_EXTENSIONS = [ + ts.Extension.Dts, + ts.Extension.Dcts, + ts.Extension.Dmts, +] as const; function getExtension(fileName: string | undefined): string | null { if (!fileName) { return null; } - return fileName.endsWith('.d.ts') ? '.d.ts' : path.extname(fileName); + + return ( + DEFINITION_EXTENSIONS.find(definitionExt => + fileName.endsWith(definitionExt), + ) ?? path.extname(fileName) + ); } function getAstFromProgram( @@ -149,7 +130,6 @@ export { createDefaultCompilerOptionsFromExtra, ensureAbsolutePath, getCanonicalFileName, - getScriptKind, getAstFromProgram, getModuleResolver, }; diff --git a/packages/typescript-estree/src/index.ts b/packages/typescript-estree/src/index.ts index a922ef199cf7..fda8b30032f5 100644 --- a/packages/typescript-estree/src/index.ts +++ b/packages/typescript-estree/src/index.ts @@ -12,6 +12,7 @@ export { simpleTraverse } from './simple-traverse'; export * from './ts-estree'; export { clearWatchCaches as clearCaches } from './create-program/createWatchProgram'; export { createProgramFromConfigFile as createProgram } from './create-program/useProvidedPrograms'; +export * from './create-program/getScriptKind'; // re-export for backwards-compat export { visitorKeys } from '@typescript-eslint/visitor-keys'; diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index 77af781a2588..9763e5894b60 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -67,7 +67,7 @@ interface ParseOptions { * Enable parsing of JSX. * For more details, see https://www.typescriptlang.org/docs/handbook/jsx.html * - * NOTE: this setting does not effect known file types (.js, .jsx, .ts, .tsx, .json) because the + * NOTE: this setting does not effect known file types (.js, .cjs, .mjs, .jsx, .ts, .mts, .cts, .tsx, .json) because the * TypeScript compiler has its own internal handling for known file extensions. * * For the exact behavior, see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser#parseroptionsecmafeaturesjsx diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index a0c952b4db52..f734c402eeb0 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -35,7 +35,7 @@ const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.8.0'; * The semver package will ignore prerelease ranges, and we don't want to explicitly document every one * List them all separately here, so we can automatically create the full string */ -const SUPPORTED_PRERELEASE_RANGES: string[] = ['4.7.0-beta', '4.7.1-rc']; +const SUPPORTED_PRERELEASE_RANGES: string[] = []; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, @@ -237,8 +237,10 @@ function applyParserOptionsToExtra(options: TSESTreeOptions): void { /** * Enable JSX - note the applicable file extension is still required */ - if (typeof options.jsx === 'boolean' && options.jsx) { - extra.jsx = true; + if (typeof options.jsx !== 'boolean') { + extra.jsx = false; + } else { + extra.jsx = options.jsx; } /** diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index 50981c203633..1d0b6ac64cad 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -365,7 +365,7 @@ tester.addFixturePatternConfig('typescript/basics', { /** * [BABEL ERRORED, BUT TS-ESTREE DID NOT] * babel hard fails on computed string enum members, but TS doesn't - * https://github.com/babel/babel/issues/12683 + * @see https://github.com/babel/babel/issues/12683 */ 'export-named-enum-computed-string', /** @@ -455,8 +455,8 @@ tester.addFixturePatternConfig('typescript/expressions', { fileType: 'ts', ignore: [ /** - * [BABEL ERRORED, BUT TS-ESTREE DID NOT] - * Babel doesn't support TS 4.7 new features yet. + * Babel produces incorrect structure for TSInstantiationExpression and optional ChainExpression + * @see https://github.com/babel/babel/issues/14613 */ 'instantiation-expression', ], @@ -492,13 +492,8 @@ tester.addFixturePatternConfig('typescript/types', { 'template-literal-type-3', 'template-literal-type-4', /** - * [BABEL ERRORED, BUT TS-ESTREE DID NOT] - * Babel doesn't support TS 4.7 new feature yet. - */ - 'conditional-infer-with-constraint', - /** - * [BABEL ERRORED, BUT TS-ESTREE DID NOT] - * Babel doesn't support TS 4.7 new features yet. + * Reported range differs between ts-estree and Babel + * @see https://github.com/babel/babel/issues/14589 */ 'optional-variance-in', 'optional-variance-out', diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 01283b2a3f01..e74d1daf3ff0 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -63,7 +63,8 @@ export function preprocessBabylonAST(ast: File): any { ], { /** - * Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231 + * Once we use babel 8, this can be removed. + * @see https://github.com/babel/babel/pull/13709 */ TSCallSignatureDeclaration(node) { if (node.typeAnnotation) { @@ -76,7 +77,8 @@ export function preprocessBabylonAST(ast: File): any { } }, /** - * Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231 + * Once we use babel 8, this can be removed. + * @see https://github.com/babel/babel/pull/13709 */ TSConstructSignatureDeclaration(node) { if (node.typeAnnotation) { @@ -89,7 +91,8 @@ export function preprocessBabylonAST(ast: File): any { } }, /** - * Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231 + * Once we use babel 8, this can be removed. + * @see https://github.com/babel/babel/pull/13709 */ TSFunctionType(node) { if (node.typeAnnotation) { @@ -102,7 +105,8 @@ export function preprocessBabylonAST(ast: File): any { } }, /** - * Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231 + * Once we use babel 8, this can be removed. + * @see https://github.com/babel/babel/pull/13709 */ TSConstructorType(node) { if (node.typeAnnotation) { @@ -115,7 +119,8 @@ export function preprocessBabylonAST(ast: File): any { } }, /** - * Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231 + * Once we use babel 8, this can be removed. + * @see https://github.com/babel/babel/pull/13709 */ TSMethodSignature(node) { if (node.typeAnnotation) { @@ -150,7 +155,11 @@ export function preprocessBabylonAST(ast: File): any { type: AST_NODE_TYPES.Identifier, }; } - // Babel does not support TS 4.7 optional variance yet. + /** + * TS 4.7: optional variance + * babel: sets in/out property as true/undefined + * ts-estree: sets in/out property as true/false + */ if (!node.in) { node.in = false; } @@ -169,15 +178,14 @@ export function preprocessBabylonAST(ast: File): any { } /** * TS 4.3: overrides on class members - * Babel doesn't ever emit a false override flag + * babel: sets override property as true/undefined + * ts-estree: sets override property as true/false */ if (node.override == null) { node.override = false; } }, PropertyDefinition(node) { - // babel does not - // node.type = AST_NODE_TYPES.PropertyDefinition; /** * Babel: ClassProperty + abstract: true * ts-estree: TSAbstractClassProperty @@ -204,6 +212,10 @@ export function preprocessBabylonAST(ast: File): any { } }, TSExpressionWithTypeArguments(node, parent: any) { + /** + * Babel: TSExpressionWithTypeArguments + * ts-estree: TSClassImplements or TSInterfaceHeritage + */ if (parent.type === AST_NODE_TYPES.TSInterfaceDeclaration) { node.type = AST_NODE_TYPES.TSInterfaceHeritage; } else if ( @@ -271,7 +283,7 @@ export function preprocessBabylonAST(ast: File): any { }, /** * babel 7.17.x introduced index property to location data to 2 node types - * TODO: report this to babel + * @see https://github.com/babel/babel/issues/14590 */ TSEnumDeclaration(node: any) { if (node.loc?.start?.index) { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 12e8316d7b6f..16e81894b386 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -2786,6 +2786,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/typeof.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/typeof-with-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/union-intersection.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/union-type.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/types/typeof-with-type-parameters.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/types/typeof-with-type-parameters.src.ts.shot new file mode 100644 index 000000000000..4215d60c3938 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/types/typeof-with-type-parameters.src.ts.shot @@ -0,0 +1,423 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript types typeof-with-type-parameters.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 4, + 20, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 20, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "exprName": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "y", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 17, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "name": "z", + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + }, + "type": "TSQualifiedName", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 20, + ], + "type": "TSTypeQuery", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "w", + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + }, + "typeParameters": undefined, + }, + ], + "range": Array [ + 17, + 20, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + }, + }, + "init": null, + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 20, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 21, + ], + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 22, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 13, + ], + "type": "Keyword", + "value": "typeof", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + "value": "z", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + "value": "w", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/types/typeof.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/types/typeof.src.ts.shot index 58a01f14e00c..43036c5b34a0 100644 --- a/packages/typescript-estree/tests/snapshots/typescript/types/typeof.src.ts.shot +++ b/packages/typescript-estree/tests/snapshots/typescript/types/typeof.src.ts.shot @@ -108,6 +108,7 @@ Object { 17, ], "type": "TSTypeQuery", + "typeParameters": undefined, }, }, }, diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index 1c374c4ca114..ad1722e1ce38 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/utils diff --git a/packages/utils/package.json b/packages/utils/package.json index 502ddbdea2c1..2446bcf7dbd3 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/utils", - "version": "5.26.0", + "version": "5.27.0", "description": "Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -33,16 +33,16 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.26.0", - "@typescript-eslint/types": "5.26.0", - "@typescript-eslint/typescript-estree": "5.26.0", + "@typescript-eslint/scope-manager": "5.27.0", + "@typescript-eslint/types": "5.27.0", + "@typescript-eslint/typescript-estree": "5.27.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, diff --git a/packages/utils/src/ts-eslint/Linter.ts b/packages/utils/src/ts-eslint/Linter.ts index 77c338f5a753..c2a8e67fe3a3 100644 --- a/packages/utils/src/ts-eslint/Linter.ts +++ b/packages/utils/src/ts-eslint/Linter.ts @@ -76,7 +76,7 @@ declare class LinterBase { /** * Performs multiple autofix passes over the text until as many fixes as possible have been applied. - * @param text The source text to apply fixes to. + * @param code The source text to apply fixes to. * @param config The ESLint config object to use. * @param options The ESLint options object to use. * @returns The result of the fix operation as returned from the SourceCodeFixer. @@ -316,7 +316,7 @@ namespace Linter { export interface ESLintParseResult { ast: TSESTree.Program; - parserServices?: ParserServices; + services?: ParserServices; scopeManager?: Scope.ScopeManager; visitorKeys?: SourceCode.VisitorKeys; } diff --git a/packages/visitor-keys/CHANGELOG.md b/packages/visitor-keys/CHANGELOG.md index 3447d5fcbe77..26187611be11 100644 --- a/packages/visitor-keys/CHANGELOG.md +++ b/packages/visitor-keys/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index f7b0b512ace4..fa44802f4d47 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/visitor-keys", - "version": "5.26.0", + "version": "5.27.0", "description": "Visitor keys used to help traverse the TypeScript-ESTree AST", "keywords": [ "eslint", @@ -32,13 +32,13 @@ "postbuild": "downlevel-dts dist _ts3.4/dist", "clean": "tsc -b tsconfig.build.json --clean", "postclean": "rimraf dist && rimraf _ts3.4 && rimraf coverage", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "lint": "eslint . --ignore-path='../../.eslintignore'", "test": "jest --coverage", "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "5.26.0", + "@typescript-eslint/types": "5.27.0", "eslint-visitor-keys": "^3.3.0" }, "devDependencies": { diff --git a/packages/website-eslint/CHANGELOG.md b/packages/website-eslint/CHANGELOG.md index 046524952cbb..44bb0b1b9178 100644 --- a/packages/website-eslint/CHANGELOG.md +++ b/packages/website-eslint/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package @typescript-eslint/website-eslint diff --git a/packages/website-eslint/package.json b/packages/website-eslint/package.json index cdb3e2847d48..eedef41c64b9 100644 --- a/packages/website-eslint/package.json +++ b/packages/website-eslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/website-eslint", - "version": "5.26.0", + "version": "5.27.0", "private": true, "description": "ESLint which works in browsers.", "engines": { @@ -13,22 +13,22 @@ ], "scripts": { "build": "rollup --config=rollup.config.js", - "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore" + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore" }, "dependencies": { - "@typescript-eslint/types": "5.26.0", - "@typescript-eslint/utils": "5.26.0" + "@typescript-eslint/types": "5.27.0", + "@typescript-eslint/utils": "5.27.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", "@rollup/pluginutils": "^4.2.1", - "@typescript-eslint/eslint-plugin": "5.26.0", - "@typescript-eslint/parser": "5.26.0", - "@typescript-eslint/scope-manager": "5.26.0", - "@typescript-eslint/typescript-estree": "5.26.0", - "@typescript-eslint/visitor-keys": "5.26.0", + "@typescript-eslint/eslint-plugin": "5.27.0", + "@typescript-eslint/parser": "5.27.0", + "@typescript-eslint/scope-manager": "5.27.0", + "@typescript-eslint/typescript-estree": "5.27.0", + "@typescript-eslint/visitor-keys": "5.27.0", "eslint": "*", "rollup": "^2.72.1", "semver": "^7.3.7" diff --git a/packages/website-eslint/src/linter/CompilerHost.js b/packages/website-eslint/src/linter/CompilerHost.js deleted file mode 100644 index f48c77109c96..000000000000 --- a/packages/website-eslint/src/linter/CompilerHost.js +++ /dev/null @@ -1,92 +0,0 @@ -import { - getDefaultLibFileName, - ScriptKind, - createSourceFile, - ScriptTarget, -} from 'typescript'; - -function getScriptKind(isJsx, filePath) { - const extension = (/(\.[a-z]+)$/.exec(filePath)?.[0] || '').toLowerCase(); - - switch (extension) { - case '.ts': - return ScriptKind.TS; - case '.tsx': - return ScriptKind.TSX; - case '.js': - return ScriptKind.JS; - - case '.jsx': - return ScriptKind.JSX; - - case '.json': - return ScriptKind.JSON; - - default: - // unknown extension, force typescript to ignore the file extension, and respect the user's setting - return isJsx ? ScriptKind.TSX : ScriptKind.TS; - } -} - -export class CompilerHost { - constructor(libs, isJsx) { - this.files = []; - this.isJsx = isJsx || false; - - if (libs) { - for (const [key, value] of libs) { - this.files[key] = value; - } - } - } - - fileExists(name) { - return !!this.files[name]; - } - - getCanonicalFileName(name) { - return name; - } - - getCurrentDirectory() { - return '/'; - } - - getDirectories() { - return []; - } - - getDefaultLibFileName(options) { - return '/' + getDefaultLibFileName(options); - } - - getNewLine() { - return '\n'; - } - - useCaseSensitiveFileNames() { - return true; - } - - writeFile() { - return null; - } - - readFile(name) { - if (this.fileExists(name)) { - return this.files[name]; - } else { - return ''; // fallback, in case if file is not available - } - } - - getSourceFile(name) { - return createSourceFile( - name, - this.readFile(name), - ScriptTarget.Latest, - /* setParentNodes */ true, - getScriptKind(this.isJsx, name), - ); - } -} diff --git a/packages/website-eslint/src/linter/linter.js b/packages/website-eslint/src/linter/linter.js index 06a4db0d3fb2..fede1540f98c 100644 --- a/packages/website-eslint/src/linter/linter.js +++ b/packages/website-eslint/src/linter/linter.js @@ -1,74 +1,16 @@ import 'vs/language/typescript/tsWorker'; -import { parseForESLint } from './parser'; import { Linter } from 'eslint'; import rules from '@typescript-eslint/eslint-plugin/dist/rules'; -const PARSER_NAME = '@typescript-eslint/parser'; - -export function loadLinter(libs, options) { +export function createLinter() { const linter = new Linter(); - let storedAST; - let storedTsAST; - let storedScope; - - let compilerOptions = options; - - linter.defineParser(PARSER_NAME, { - parseForESLint(code, eslintOptions) { - const toParse = parseForESLint( - code, - eslintOptions, - compilerOptions, - libs, - ); - storedAST = toParse.ast; - storedTsAST = toParse.tsAst; - storedScope = toParse.scopeManager; - return toParse; - }, - // parse(code: string, options: ParserOptions): ParseForESLintResult['ast'] { - // const toParse = parseForESLint(code, options); - // storedAST = toParse.ast; - // return toParse.ast; - // }, - }); - - for (const name of Object.keys(rules)) { + for (const name in rules) { linter.defineRule(`@typescript-eslint/${name}`, rules[name]); } - - const ruleNames = Array.from(linter.getRules()).map(value => { - return { - name: value[0], - description: value[1]?.meta?.docs?.description, - }; - }); - - return { - ruleNames: ruleNames, - - updateOptions(options) { - compilerOptions = options || {}; - }, - - getScope() { - return storedScope; - }, - - getAst() { - return storedAST; - }, - - getTsAst() { - return storedTsAST; - }, - - lint(code, parserOptions, rules) { - return linter.verify(code, { - parser: PARSER_NAME, - parserOptions, - rules, - }); - }, - }; + return linter; } + +export { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; +export { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; +export { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; +export { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; diff --git a/packages/website-eslint/src/linter/parser.js b/packages/website-eslint/src/linter/parser.js deleted file mode 100644 index fc637fe65b7d..000000000000 --- a/packages/website-eslint/src/linter/parser.js +++ /dev/null @@ -1,62 +0,0 @@ -import { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; -import { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; -import { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; -import { extra } from './config.js'; -import { CompilerHost } from './CompilerHost'; -import { createProgram } from 'typescript'; - -export function createASTProgram(code, isJsx, compilerOptions, libs) { - const fileName = isJsx ? '/demo.tsx' : '/demo.ts'; - const compilerHost = new CompilerHost(libs, isJsx); - - compilerHost.files[fileName] = code; - const program = createProgram( - Object.keys(compilerHost.files), - compilerOptions, - compilerHost, - ); - const ast = program.getSourceFile(fileName); - return { - ast, - program, - }; -} - -export function parseForESLint(code, eslintOptions, compilerOptions, libs) { - const isJsx = eslintOptions.ecmaFeatures?.jsx ?? false; - - const { ast: tsAst, program } = createASTProgram( - code, - isJsx, - compilerOptions, - libs, - ); - - const { estree: ast, astMaps } = astConverter( - tsAst, - { ...extra, code, jsx: isJsx }, - true, - ); - - const services = { - hasFullTypeInformation: true, - program, - esTreeNodeToTSNodeMap: astMaps.esTreeNodeToTSNodeMap, - tsNodeToESTreeNodeMap: astMaps.tsNodeToESTreeNodeMap, - }; - - const scopeManager = analyze(ast, { - ecmaVersion: - eslintOptions.ecmaVersion === 'latest' ? 1e8 : eslintOptions.ecmaVersion, - globalReturn: eslintOptions.ecmaFeatures?.globalReturn ?? false, - sourceType: eslintOptions.sourceType ?? 'script', - }); - - return { - ast, - tsAst, - services, - scopeManager, - visitorKeys, - }; -} diff --git a/packages/website-eslint/types/index.d.ts b/packages/website-eslint/types/index.d.ts index aa5a2a43ed7f..7673f6d10a27 100644 --- a/packages/website-eslint/types/index.d.ts +++ b/packages/website-eslint/types/index.d.ts @@ -1,38 +1,13 @@ -import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; -import type { ParserOptions } from '@typescript-eslint/types'; -import type { SourceFile, CompilerOptions } from 'typescript'; - -export type LintMessage = TSESLint.Linter.LintMessage; -export type RuleFix = TSESLint.RuleFix; -export type RulesRecord = TSESLint.Linter.RulesRecord; -export type RuleEntry = TSESLint.Linter.RuleEntry; - -export interface WebLinter { - ruleNames: { name: string; description?: string }[]; - - getAst(): TSESTree.Program; - getTsAst(): SourceFile; - getScope(): Record; - updateOptions(options?: Record): void; - - lint( - code: string, - parserOptions: ParserOptions, - rules?: RulesRecord, - ): LintMessage[]; +import type { TSESLint } from '@typescript-eslint/utils'; + +import { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; +import { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; +import { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; + +export interface LintUtils { + createLinter: () => TSESLint.Linter; + analyze: typeof analyze; + visitorKeys: TSESLint.SourceCode.VisitorKeys; + astConverter: typeof astConverter; + getScriptKind: typeof getScriptKind; } - -export interface LinterLoader { - loadLinter( - libMap: Map, - compilerOptions: CompilerOptions, - ): WebLinter; -} - -export type { - DebugLevel, - EcmaVersion, - ParserOptions, - SourceType, - TSESTree, -} from '@typescript-eslint/types'; diff --git a/packages/website/CHANGELOG.md b/packages/website/CHANGELOG.md index 0d22e43b1b43..54b171d6bae6 100644 --- a/packages/website/CHANGELOG.md +++ b/packages/website/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [5.27.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.26.0...v5.27.0) (2022-05-30) + + +### Features + +* [4.7] support new extensions ([#5027](https://github.com/typescript-eslint/typescript-eslint/issues/5027)) ([efc147b](https://github.com/typescript-eslint/typescript-eslint/commit/efc147b04dce52ab17415b6a4ae4076b944b9036)) + + + + + # [5.26.0](https://github.com/typescript-eslint/typescript-eslint/compare/v5.25.0...v5.26.0) (2022-05-23) **Note:** Version bump only for package website diff --git a/packages/website/data/sponsors.json b/packages/website/data/sponsors.json index 83eb6a3568d3..d9675b816b97 100644 --- a/packages/website/data/sponsors.json +++ b/packages/website/data/sponsors.json @@ -138,7 +138,7 @@ "id": "David Johnston", "image": "https://images.opencollective.com/blacksheepcode/976d69a/avatar.png", "name": "David Johnston", - "tier": "supporter", + "tier": "contributor", "totalDonations": 12000, "website": "https://blacksheepcode.com" }, @@ -162,7 +162,7 @@ "id": "Tripwire, Inc.", "image": "https://images.opencollective.com/tripwire/7599e30/logo.png", "name": "Tripwire, Inc.", - "tier": "supporter", + "tier": "contributor", "totalDonations": 7500, "website": "https://tripwire.com" }, @@ -170,7 +170,7 @@ "id": "Evil Martians", "image": "https://images.opencollective.com/evilmartians/707ab4d/logo.png", "name": "Evil Martians", - "tier": "supporter", + "tier": "contributor", "totalDonations": 7000, "website": "https://evilmartians.com/" }, @@ -178,7 +178,7 @@ "id": "Balsa", "image": "https://images.opencollective.com/balsa/77de498/logo.png", "name": "Balsa", - "tier": "supporter", + "tier": "contributor", "totalDonations": 7000, "website": "https://balsa.com" }, @@ -186,7 +186,7 @@ "id": "Jeffrey Rennie", "image": "https://images.opencollective.com/jeffrey-rennie/avatar.png", "name": "Jeffrey Rennie", - "tier": "supporter", + "tier": "contributor", "totalDonations": 6500 }, { @@ -213,114 +213,20 @@ "totalDonations": 5000, "website": "https://Indeed.com" }, - { - "id": "Andrey Sitnik", - "image": "https://images.opencollective.com/andrey-sitnik/11aeb28/avatar.png", - "name": "Andrey Sitnik", - "tier": "contributor", - "totalDonations": 4500, - "website": "https://sitnik.ru" - }, { "id": "Corellium", "image": "https://images.opencollective.com/corellium/aa8c228/logo.png", "name": "Corellium", - "tier": "supporter", + "tier": "contributor", "totalDonations": 3600, "website": "https://www.corellium.com" }, - { - "id": "Kamino Ryo", - "image": "https://images.opencollective.com/kaminoryo/d1d9ff5/avatar.png", - "name": "Kamino Ryo", - "tier": "contributor", - "totalDonations": 3000 - }, - { - "id": "Kevin Smith", - "image": "https://images.opencollective.com/kevin-smith1/a343791/avatar.png", - "name": "Kevin Smith", - "tier": "contributor", - "totalDonations": 2500 - }, - { - "id": "Dani Gellis", - "image": "https://images.opencollective.com/dani-gellis1/avatar.png", - "name": "Dani Gellis", - "tier": "contributor", - "totalDonations": 2500 - }, - { - "id": "38elements", - "image": "https://images.opencollective.com/38elements/5dfbefe/avatar.png", - "name": "38elements", - "tier": "contributor", - "totalDonations": 2200, - "website": "https://japanese-document.github.io/react-redux/connect.html" - }, - { - "id": "Gaëtan Bloch", - "image": "https://images.opencollective.com/gaetan-bloch/c5cfcb2/avatar.png", - "name": "Gaëtan Bloch", - "tier": "contributor", - "totalDonations": 2100 - }, - { - "id": "Softwear, BV", - "image": "https://images.opencollective.com/softwear_dev/dc2d34e/logo.png", - "name": "Softwear, BV", - "tier": "contributor", - "totalDonations": 2000, - "website": "https://www.softwearconnect.com" - }, - { - "id": "Sean Lindsay", - "image": "https://images.opencollective.com/sean-lindsay/avatar.png", - "name": "Sean Lindsay", - "tier": "contributor", - "totalDonations": 2000 - }, - { - "id": "Jane Doe", - "image": "https://images.opencollective.com/jane-doe/avatar.png", - "name": "Jane Doe", - "tier": "contributor", - "totalDonations": 2000 - }, { "id": "MySportsInjury", "image": "https://images.opencollective.com/my-sports-injury-ltd/518c583/logo.png", "name": "MySportsInjury", - "tier": "supporter", + "tier": "contributor", "totalDonations": 1500, "website": "https://www.mysportsinjury.co.uk" - }, - { - "id": "Philip Keiter", - "image": "https://images.opencollective.com/philip-keiter/1c359c0/avatar.png", - "name": "Philip Keiter", - "tier": "contributor", - "totalDonations": 1000 - }, - { - "id": "Toru Shimogaisho", - "image": "https://images.opencollective.com/gaishimo/f620536/avatar.png", - "name": "Toru Shimogaisho", - "tier": "contributor", - "totalDonations": 1000 - }, - { - "id": "Kazuhiro Kobayashi", - "image": "https://images.opencollective.com/kazuhiro-kobayashi/a1eeb73/avatar.png", - "name": "Kazuhiro Kobayashi", - "tier": "contributor", - "totalDonations": 1000 - }, - { - "id": "Masafumi Koba", - "image": "https://images.opencollective.com/ybiquitous/6a6913d/avatar.png", - "name": "Masafumi Koba", - "tier": "contributor", - "totalDonations": 1000 } ] diff --git a/packages/website/package.json b/packages/website/package.json index 35309c4e44df..6c2be083e120 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -1,12 +1,12 @@ { "name": "website", - "version": "5.26.0", + "version": "5.27.0", "private": true, "scripts": { "build": "docusaurus build", "clear": "docusaurus clear", "format": "prettier --write \"./**/*.{md,mdx,ts,js,tsx,jsx}\" --ignore-path ../../.prettierignore", - "lint": "eslint . --ext .js,.ts --ignore-path ../../.eslintignore", + "lint": "eslint . --ignore-path ../../.eslintignore", "serve": "docusaurus serve", "start": "docusaurus start", "swizzle": "docusaurus swizzle", @@ -14,13 +14,13 @@ "test:open": "cypress open" }, "dependencies": { - "@babel/runtime": "7.18.0", - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/preset-classic": "2.0.0-beta.20", - "@docusaurus/remark-plugin-npm2yarn": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", + "@babel/runtime": "^7.18.3", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/preset-classic": "2.0.0-beta.21", + "@docusaurus/remark-plugin-npm2yarn": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", "@mdx-js/react": "1.6.22", - "@typescript-eslint/website-eslint": "5.26.0", + "@typescript-eslint/website-eslint": "5.27.0", "clsx": "^1.1.1", "eslint": "*", "json5": "^2.2.1", @@ -32,11 +32,11 @@ "typescript": "*" }, "devDependencies": { - "@docusaurus/module-type-aliases": "^2.0.0-beta.18", + "@docusaurus/module-type-aliases": "^2.0.0-beta.21", "@types/react": "^18.0.9", "@types/react-helmet": "^6.1.5", "@types/react-router-dom": "^5.3.3", - "copy-webpack-plugin": "^10.2.4", + "copy-webpack-plugin": "^11.0.0", "cypress": "8.3.0", "cypress-axe": "^0.14.0", "eslint-plugin-jsx-a11y": "^6.5.1", diff --git a/packages/website/src/components/ASTViewerESTree.tsx b/packages/website/src/components/ASTViewerESTree.tsx index 7d46efdfb110..855235eba0b4 100644 --- a/packages/website/src/components/ASTViewerESTree.tsx +++ b/packages/website/src/components/ASTViewerESTree.tsx @@ -1,13 +1,14 @@ -import React, { useEffect, useState } from 'react'; +import React, { useMemo } from 'react'; import ASTViewer from './ast/ASTViewer'; -import type { ASTViewerBaseProps, ASTViewerModelMap } from './ast/types'; -import type { TSESTree } from '@typescript-eslint/website-eslint'; +import type { ASTViewerBaseProps } from './ast/types'; +import type { TSESTree } from '@typescript-eslint/utils'; + import { serialize } from './ast/serializer/serializer'; import { createESTreeSerializer } from './ast/serializer/serializerESTree'; export interface ASTESTreeViewerProps extends ASTViewerBaseProps { - readonly value: TSESTree.BaseNode | string; + readonly value: TSESTree.BaseNode; } export default function ASTViewerESTree({ @@ -15,16 +16,10 @@ export default function ASTViewerESTree({ position, onSelectNode, }: ASTESTreeViewerProps): JSX.Element { - const [model, setModel] = useState(''); - - useEffect(() => { - if (typeof value === 'string') { - setModel(value); - } else { - const astSerializer = createESTreeSerializer(); - setModel(serialize(value, astSerializer)); - } - }, [value]); + const model = useMemo( + () => serialize(value, createESTreeSerializer()), + [value], + ); return ( diff --git a/packages/website/src/components/ASTViewerScope.tsx b/packages/website/src/components/ASTViewerScope.tsx index b14514855381..9d5dff8fc5af 100644 --- a/packages/website/src/components/ASTViewerScope.tsx +++ b/packages/website/src/components/ASTViewerScope.tsx @@ -1,29 +1,23 @@ -import React, { useEffect, useState } from 'react'; +import React, { useMemo } from 'react'; import ASTViewer from './ast/ASTViewer'; -import type { ASTViewerBaseProps, ASTViewerModelMap } from './ast/types'; +import type { ASTViewerBaseProps } from './ast/types'; import { serialize } from './ast/serializer/serializer'; import { createScopeSerializer } from './ast/serializer/serializerScope'; export interface ASTScopeViewerProps extends ASTViewerBaseProps { - readonly value: Record | string; + readonly value: Record; } export default function ASTViewerScope({ value, onSelectNode, }: ASTScopeViewerProps): JSX.Element { - const [model, setModel] = useState(''); - - useEffect(() => { - if (typeof value === 'string') { - setModel(value); - } else { - const scopeSerializer = createScopeSerializer(); - setModel(serialize(value, scopeSerializer)); - } - }, [value]); + const model = useMemo( + () => serialize(value, createScopeSerializer()), + [value], + ); return ; } diff --git a/packages/website/src/components/ASTViewerTS.tsx b/packages/website/src/components/ASTViewerTS.tsx index d33e524366aa..8cd3f15ce5a8 100644 --- a/packages/website/src/components/ASTViewerTS.tsx +++ b/packages/website/src/components/ASTViewerTS.tsx @@ -7,7 +7,7 @@ import { serialize } from './ast/serializer/serializer'; import { createTsSerializer } from './ast/serializer/serializerTS'; export interface ASTTsViewerProps extends ASTViewerBaseProps { - readonly value: SourceFile | string; + readonly value: SourceFile; } function extractEnum( @@ -41,22 +41,18 @@ export default function ASTViewerTS({ const [typeFlags] = useState(() => extractEnum(window.ts.TypeFlags)); useEffect(() => { - if (typeof value === 'string') { - setModel(value); - } else { - const scopeSerializer = createTsSerializer( - value, - syntaxKind, - ['NodeFlags', nodeFlags], - ['TokenFlags', tokenFlags], - ['ModifierFlags', modifierFlags], - ['ObjectFlags', objectFlags], - ['SymbolFlags', symbolFlags], - ['FlowFlags', flowFlags], - ['TypeFlags', typeFlags], - ); - setModel(serialize(value, scopeSerializer)); - } + const scopeSerializer = createTsSerializer( + value, + syntaxKind, + ['NodeFlags', nodeFlags], + ['TokenFlags', tokenFlags], + ['ModifierFlags', modifierFlags], + ['ObjectFlags', objectFlags], + ['SymbolFlags', symbolFlags], + ['FlowFlags', flowFlags], + ['TypeFlags', typeFlags], + ); + setModel(serialize(value, scopeSerializer)); }, [value, syntaxKind]); return ( diff --git a/packages/website/src/components/EditorTabs.tsx b/packages/website/src/components/EditorTabs.tsx new file mode 100644 index 000000000000..a0b81e9dc058 --- /dev/null +++ b/packages/website/src/components/EditorTabs.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import type { TabType } from './types'; +import styles from './Playground.module.css'; +import EditIcon from '@site/src/icons/edit.svg'; + +export interface FileTabsProps { + readonly tabs: TabType[]; + readonly activeTab: TabType; + readonly change: (tab: TabType) => void; + readonly showModal: () => void; +} + +export default function EditorTabs({ + tabs, + activeTab, + change, + showModal, +}: FileTabsProps): JSX.Element { + return ( +
+
+ {tabs.map(item => { + return ( + + ); + })} +
+ {activeTab !== 'code' && ( + + )} +
+ ); +} diff --git a/packages/website/src/components/ErrorsViewer.module.css b/packages/website/src/components/ErrorsViewer.module.css new file mode 100644 index 000000000000..fab012b69e88 --- /dev/null +++ b/packages/website/src/components/ErrorsViewer.module.css @@ -0,0 +1,21 @@ +.list { + font-family: var(--ifm-font-family-monospace); + background: transparent; + border: none; + padding-left: 1.5rem; + padding-right: 1.5rem; + font-size: 13px; + line-height: 18px; + letter-spacing: 0; + font-feature-settings: 'liga' 0, 'calt' 0; + box-sizing: border-box; + white-space: break-spaces; + margin: 0; +} + +.fixer { + margin: 0.5rem 1.5rem; + display: flex; + justify-content: space-between; + align-items: center; +} diff --git a/packages/website/src/components/ErrorsViewer.tsx b/packages/website/src/components/ErrorsViewer.tsx new file mode 100644 index 000000000000..566f1b83fdc4 --- /dev/null +++ b/packages/website/src/components/ErrorsViewer.tsx @@ -0,0 +1,111 @@ +import React, { useEffect, useMemo, useState } from 'react'; +import type Monaco from 'monaco-editor'; +import type { ErrorItem } from './types'; + +import styles from './ErrorsViewer.module.css'; + +export interface ErrorsViewerProps { + readonly value?: ErrorItem[]; +} + +export interface ErrorBlockProps { + readonly item: ErrorItem; + readonly setIsLocked: (value: boolean) => void; + readonly isLocked: boolean; +} + +function severityClass(severity: Monaco.MarkerSeverity): string { + switch (severity) { + case 8: + return 'danger'; + case 4: + return 'warning'; + case 2: + return 'note'; + } + return 'info'; +} + +function groupErrorItems(items: ErrorItem[]): [string, ErrorItem[]][] { + return Object.entries( + items.reduce>((acc, obj) => { + if (!acc[obj.group]) { + acc[obj.group] = []; + } + acc[obj.group].push(obj); + return acc; + }, {}), + ).sort(([a], [b]) => a.localeCompare(b)); +} + +function ErrorBlock({ + item, + setIsLocked, + isLocked, +}: ErrorBlockProps): JSX.Element { + return ( +
+
+
+
+ {item.message} {item.location} +
+ {item.hasFixers && ( +
+ {item.fixers.map((fixer, index) => ( +
+ > {fixer.message} + +
+ ))} +
+ )} +
+
+
+ ); +} + +export default function ErrorsViewer({ + value, +}: ErrorsViewerProps): JSX.Element { + const model = useMemo( + () => (value ? groupErrorItems(value) : undefined), + [value], + ); + + const [isLocked, setIsLocked] = useState(false); + + useEffect(() => { + setIsLocked(false); + }, [value]); + + return ( +
+ {model?.map(([group, data]) => { + return ( +
+

{group}

+ {data.map((item, index) => ( + + ))} +
+ ); + })} +
+ ); +} diff --git a/packages/website/src/components/FinancialContributors/Sponsors/styles.module.css b/packages/website/src/components/FinancialContributors/Sponsors/styles.module.css index 0373225a2b50..9c337f1ead6d 100644 --- a/packages/website/src/components/FinancialContributors/Sponsors/styles.module.css +++ b/packages/website/src/components/FinancialContributors/Sponsors/styles.module.css @@ -39,9 +39,15 @@ width: 120px; } +.tier-supporter, +.tier-contributor { + align-items: center; + gap: 4px 16px; +} + .tier-supporter img { - max-height: 45px; - width: 45px; + max-height: 60px; + width: 60px; } .tier-contributor img { diff --git a/packages/website/src/components/OptionsSelector.tsx b/packages/website/src/components/OptionsSelector.tsx index 86c842965073..f3a579df30b4 100644 --- a/packages/website/src/components/OptionsSelector.tsx +++ b/packages/website/src/components/OptionsSelector.tsx @@ -1,27 +1,21 @@ /* eslint-disable jsx-a11y/label-has-associated-control */ -import React, { useCallback, useState } from 'react'; +import React, { useCallback } from 'react'; -import ConfigEslint from './config/ConfigEslint'; -import ConfigTypeScript from './config/ConfigTypeScript'; import Expander from './layout/Expander'; import Dropdown from './inputs/Dropdown'; import Checkbox from './inputs/Checkbox'; import Tooltip from './inputs/Tooltip'; -import EditIcon from '@site/src/icons/edit.svg'; import CopyIcon from '@site/src/icons/copy.svg'; import useDebouncedToggle from './hooks/useDebouncedToggle'; -import { createMarkdown } from './lib/markdown'; - -import type { RuleDetails } from './types'; +import { createMarkdown, createMarkdownParams } from './lib/markdown'; import styles from './OptionsSelector.module.css'; -import type { CompilerFlags, ConfigModel, RulesRecord } from './types'; +import type { ConfigModel } from './types'; export interface OptionsSelectorParams { - readonly ruleOptions: RuleDetails[]; readonly state: ConfigModel; readonly setState: (cfg: Partial) => void; readonly tsVersions: readonly string[]; @@ -36,14 +30,11 @@ const ASTOptions = [ ] as const; function OptionsSelector({ - ruleOptions, state, setState, tsVersions, isLoading, }: OptionsSelectorParams): JSX.Element { - const [eslintModal, setEslintModal] = useState(false); - const [typeScriptModal, setTypeScriptModal] = useState(false); const [copyLink, setCopyLink] = useDebouncedToggle(false); const [copyMarkdown, setCopyMarkdown] = useDebouncedToggle(false); @@ -54,26 +45,6 @@ function OptionsSelector({ [setState], ); - const updateRules = useCallback( - (rules?: RulesRecord) => { - if (rules) { - setState({ rules: rules }); - } - setEslintModal(false); - }, - [setState], - ); - - const updateTsConfig = useCallback( - (config?: CompilerFlags) => { - if (config) { - setState({ tsConfig: config }); - } - setTypeScriptModal(false); - }, - [setState], - ); - const copyLinkToClipboard = useCallback(() => { void navigator.clipboard .writeText(document.location.toString()) @@ -97,8 +68,8 @@ function OptionsSelector({ } window .open( - `https://github.com/typescript-eslint/typescript-eslint/issues/new?body=${encodeURIComponent( - createMarkdown(state), + `https://github.com/typescript-eslint/typescript-eslint/issues/new?${createMarkdownParams( + state, )}`, '_blank', ) @@ -107,19 +78,6 @@ function OptionsSelector({ return ( <> - {state.rules && ruleOptions.length > 0 && ( - - )} - - - diff --git a/packages/website/src/components/Playground.module.css b/packages/website/src/components/Playground.module.css index ded7538d260f..b6c4e1904c03 100644 --- a/packages/website/src/components/Playground.module.css +++ b/packages/website/src/components/Playground.module.css @@ -1,17 +1,18 @@ +:root { + --playground-main-color: var(--ifm-background-surface-color); + --playground-secondary-color: var(--ifm-color-emphasis-100); +} + .options { width: 20rem; - background: var(--ifm-background-surface-color); + background: var(--playground-main-color); overflow: auto; } .sourceCode { height: 100%; width: 50%; - border: 1px solid var(--ifm-color-emphasis-100); -} - -.sourceCodeStandalone { - width: 100%; + border: 1px solid var(--playground-secondary-color); } .codeBlocks { @@ -24,7 +25,7 @@ .astViewer { height: 100%; width: 50%; - border: 1px solid var(--ifm-color-emphasis-100); + border: 1px solid var(--playground-secondary-color); padding: 0; overflow: auto; word-wrap: initial; @@ -41,3 +42,67 @@ top: var(--ifm-navbar-height); z-index: calc(var(--ifm-z-index-fixed) - 1); } + +.tabContainer { + display: flex; + justify-content: space-between; + background: var(--playground-main-color); + border-bottom: 1px solid var(--playground-secondary-color); +} + +.tabCode { + height: calc(100%); +} + +.tabStyle { + border: none; + border-right: 1px solid var(--playground-secondary-color); + background: var(--playground-main-color); + color: var(--ifm-color-emphasis-700); + padding: 0.5rem 1rem; + cursor: pointer; +} + +.tabStyle svg { + margin-left: 0.3rem; +} + +.tabStyle:hover { + background: var(--playground-secondary-color); +} + +.tabStyle:disabled { + background: var(--playground-secondary-color); + color: var(--ifm-color-emphasis-900); +} + +@media only screen and (max-width: 996px) { + .codeContainer { + display: block; + width: 100%; + position: static; + } + .codeBlocks { + display: block; + width: 100%; + } + + .options { + width: 100%; + } + + .tabCode { + height: calc(30rem - 3.2rem); + } + + .astViewer, + .sourceCode { + height: 30rem; + width: 100%; + } + + .astViewer { + height: auto; + max-height: 30rem; + } +} diff --git a/packages/website/src/components/Playground.tsx b/packages/website/src/components/Playground.tsx index 6f28f21d36e9..e08c3e3c274a 100644 --- a/packages/website/src/components/Playground.tsx +++ b/packages/website/src/components/Playground.tsx @@ -1,4 +1,4 @@ -import React, { useReducer, useState } from 'react'; +import React, { useCallback, useReducer, useState } from 'react'; import type Monaco from 'monaco-editor'; import clsx from 'clsx'; import { useColorMode } from '@docusaurus/theme-common'; @@ -15,11 +15,25 @@ import { shallowEqual } from './lib/shallowEqual'; import ASTViewerESTree from './ASTViewerESTree'; import ASTViewerTS from './ASTViewerTS'; -import type { RuleDetails, SelectedRange } from './types'; +import type { + RuleDetails, + SelectedRange, + ErrorItem, + TabType, + ConfigModel, +} from './types'; -import type { TSESTree } from '@typescript-eslint/website-eslint'; +import type { TSESTree } from '@typescript-eslint/utils'; import type { SourceFile } from 'typescript'; import ASTViewerScope from '@site/src/components/ASTViewerScope'; +import ErrorsViewer from '@site/src/components/ErrorsViewer'; +import EditorTabs from '@site/src/components/EditorTabs'; +import ConfigEslint from '@site/src/components/config/ConfigEslint'; +import ConfigTypeScript from '@site/src/components/config/ConfigTypeScript'; +import { + defaultEslintConfig, + defaultTsConfig, +} from '@site/src/components/config/utils'; function rangeReducer( prevState: T, @@ -44,54 +58,84 @@ function Playground(): JSX.Element { showAST: false, sourceType: 'module', code: '', - ts: process.env.TS_VERSION, - rules: {}, - tsConfig: {}, + ts: process.env.TS_VERSION!, + tsconfig: defaultTsConfig, + eslintrc: defaultEslintConfig, }); - const { isDarkTheme } = useColorMode(); - const [esAst, setEsAst] = useState(); - const [tsAst, setTsAST] = useState(); - const [scope, setScope] = useState | string | null>(); + const { colorMode } = useColorMode(); + const [esAst, setEsAst] = useState(); + const [tsAst, setTsAST] = useState(); + const [scope, setScope] = useState | null>(); + const [markers, setMarkers] = useState(); const [ruleNames, setRuleNames] = useState([]); const [isLoading, setIsLoading] = useState(true); const [tsVersions, setTSVersion] = useState([]); const [selectedRange, setSelectedRange] = useReducer(rangeReducer, null); const [position, setPosition] = useState(null); + const [activeTab, setTab] = useState('code'); + const [showModal, setShowModal] = useState(false); + + const updateModal = useCallback( + (config?: Partial) => { + if (config) { + setState(config); + } + setShowModal(false); + }, + [setState], + ); return (
+ {ruleNames.length > 0 && ( + + )} +
-
+
{isLoading && } - + setShowModal(activeTab)} + /> +
+ +
setState({ code: code })} + onChange={setState} onLoaded={(ruleNames, tsVersions): void => { setRuleNames(ruleNames); setTSVersion(tsVersions); @@ -100,31 +144,29 @@ function Playground(): JSX.Element { onSelect={setPosition} />
- {state.showAST && ( -
- {(tsAst && state.showAST === 'ts' && ( - + {(state.showAST === 'ts' && tsAst && ( + + )) || + (state.showAST === 'scope' && scope && ( + )) || - (state.showAST === 'scope' && scope && ( - - )) || - (esAst && ( - - ))} -
- )} + (state.showAST === 'es' && esAst && ( + + )) || } +
); diff --git a/packages/website/src/components/ast/serializer/serializerESTree.ts b/packages/website/src/components/ast/serializer/serializerESTree.ts index 7f467757c8a3..76aabfd024bd 100644 --- a/packages/website/src/components/ast/serializer/serializerESTree.ts +++ b/packages/website/src/components/ast/serializer/serializerESTree.ts @@ -1,6 +1,6 @@ import type { ASTViewerModel, Serializer } from '../types'; +import type { TSESTree } from '@typescript-eslint/utils'; import { isRecord } from '../utils'; -import type { TSESTree } from '@typescript-eslint/website-eslint'; export const propsToFilter = ['parent', 'comments', 'tokens']; diff --git a/packages/website/src/components/ast/serializer/serializerScope.ts b/packages/website/src/components/ast/serializer/serializerScope.ts index 176f49f92c5c..b000aba7db1e 100644 --- a/packages/website/src/components/ast/serializer/serializerScope.ts +++ b/packages/website/src/components/ast/serializer/serializerScope.ts @@ -1,5 +1,5 @@ import type { ASTViewerModel, Serializer, SelectedRange } from '../types'; -import type { TSESTree } from '@typescript-eslint/website-eslint'; +import type { TSESTree } from '@typescript-eslint/utils'; import { isRecord } from '../utils'; function isESTreeNode( diff --git a/packages/website/src/components/ast/serializer/serializerTS.ts b/packages/website/src/components/ast/serializer/serializerTS.ts index b89d6e0e1a44..66cffe82b92a 100644 --- a/packages/website/src/components/ast/serializer/serializerTS.ts +++ b/packages/website/src/components/ast/serializer/serializerTS.ts @@ -20,6 +20,7 @@ export const propsToFilter = [ 'jsDocComment', 'lineMap', 'externalModuleIndicator', + 'setExternalModuleIndicator', 'bindDiagnostics', 'transformFlags', 'resolvedModules', diff --git a/packages/website/src/components/config/ConfigEditor.tsx b/packages/website/src/components/config/ConfigEditor.tsx index 062e1ac21fde..43bfcadd9bcd 100644 --- a/packages/website/src/components/config/ConfigEditor.tsx +++ b/packages/website/src/components/config/ConfigEditor.tsx @@ -1,6 +1,5 @@ import React, { useCallback, useEffect, useReducer, useState } from 'react'; import clsx from 'clsx'; -import { parse } from 'json5'; import styles from './ConfigEditor.module.css'; @@ -27,32 +26,9 @@ export interface ConfigEditorProps { readonly values: ConfigEditorValues; readonly isOpen: boolean; readonly header: string; - readonly jsonField: string; readonly onClose: (config: ConfigEditorValues) => void; } -function reducerJson( - _state: string, - action: string | { field: string; value: ConfigEditorValues }, -): string { - if (typeof action === 'string') { - return action; - } else if (action && typeof action === 'object') { - return JSON.stringify( - { - [action.field]: action.value, - }, - null, - 2, - ); - } - throw new Error(); -} - -function isRecord(data: unknown): data is Record { - return Boolean(data && typeof data === 'object'); -} - function reducerObject( state: ConfigEditorValues, action: @@ -62,8 +38,7 @@ function reducerObject( checked: boolean; default: unknown[] | undefined; name: string; - } - | { type: 'json'; field: string; code: string }, + }, ): ConfigEditorValues { switch (action.type) { case 'init': { @@ -78,21 +53,6 @@ function reducerObject( } return newState; } - case 'json': { - try { - const parsed: unknown = parse(action.code); - if (isRecord(parsed)) { - const item = parsed[action.field]; - if (item && isRecord(item)) { - return item; - } - } - } catch { - // eslint-disable-next-line no-console - console.error('ERROR parsing json'); - } - return state; - } } } @@ -114,25 +74,12 @@ function isDefault(value: unknown, defaults?: unknown[]): boolean { function ConfigEditor(props: ConfigEditorProps): JSX.Element { const [filter, setFilter] = useState(''); - const [editJson, setEditJson] = useState(false); const [config, setConfig] = useReducer(reducerObject, {}); - const [jsonCode, setJsonCode] = useReducer(reducerJson, ''); const [filterInput, setFilterFocus] = useFocus(); - const [jsonInput, setJsonFocus] = useFocus(); const onClose = useCallback(() => { - if (editJson) { - props.onClose( - reducerObject(config, { - type: 'json', - field: props.jsonField, - code: jsonCode, - }), - ); - } else { - props.onClose(config); - } - }, [props.onClose, props.jsonField, jsonCode, config]); + props.onClose(config); + }, [props.onClose, config]); useEffect(() => { setConfig({ type: 'init', config: props.values }); @@ -140,93 +87,57 @@ function ConfigEditor(props: ConfigEditorProps): JSX.Element { useEffect(() => { if (props.isOpen) { - if (!editJson) { - setFilterFocus(); - } else { - setJsonFocus(); - } - } - }, [editJson, props.isOpen]); - - const changeEditType = useCallback(() => { - if (editJson) { - setConfig({ type: 'json', field: props.jsonField, code: jsonCode }); - } else { - setJsonCode({ field: props.jsonField, value: config }); + setFilterFocus(); } - setEditJson(!editJson); - }, [editJson, config, jsonCode, props.jsonField]); + }, [props.isOpen]); return (
- {!editJson && ( - - )} - -
- {editJson && ( -