Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint-plugin-import #102

Merged
merged 2 commits into from Feb 27, 2024
Merged

Add eslint-plugin-import #102

merged 2 commits into from Feb 27, 2024

Conversation

alice-byb
Copy link
Contributor

Added eslint-plugin-import along with specific rules for:

  • ordering react at the top
  • ordering mocks where they belong

Copy link

codeclimate bot commented Feb 27, 2024

Code Climate has analyzed commit 44ea34f and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 61.0% (0.0% change).

View more on Code Climate.

Copy link

New dependencies added: eslint-import-resolver-typescript and eslint-plugin-import.

eslint-import-resolver-typescript

Used in package.json
Author: Alex Gorbatchev Description: This plugin adds `TypeScript` support to `eslint-plugin-import`
License: ISC Homepage: https://github.com/import-js/eslint-import-resolver-typescript#readme
Keywords: typescript, eslint, import, resolver and plugin
Updated: 5 months ago Created: over 6 years ago
Releases: 43 Maintainers: 3
Direct Dependencies: debug, enhanced-resolve, eslint-module-utils, fast-glob, get-tsconfig, is-core-module, is-glob
README

eslint-import-resolver-typescript

GitHub Actions
type-coverage
npm
GitHub Release

Conventional Commits
Renovate enabled
JavaScript Style Guide
Code Style: Prettier
changesets

This plugin adds TypeScript support to eslint-plugin-import (Or maybe you want to try eslint-plugin-i for faster speed)

This means you can:

  • import/require files with extension .cts/.mts/.ts/.tsx/.d.cts/.d.mts/.d.ts
  • Use paths defined in tsconfig.json
  • Prefer resolving @types/* definitions over plain .js/.jsx
  • Multiple tsconfigs support just like normal
  • imports/exports fields support in package.json

TOC

Notice

After version 2.0.0, .d.ts will take higher priority then normal .js/.jsx files on resolving node_modules packages in favor of @types/* definitions or its own definition.

If you're facing some problems on rules import/default or import/named from eslint-plugin-import, do not post any issue here, because they are just working exactly as expected on our sides, take import-js/eslint-plugin-import#1525 as reference or post a new issue to eslint-plugin-import instead.

Installation

# npm
npm i -D eslint-plugin-import eslint-import-resolver-typescript

# pnpm
pnpm i -D eslint-plugin-import eslint-import-resolver-typescript

# yarn
yarn add -D eslint-plugin-import eslint-import-resolver-typescript

Configuration

Add the following to your .eslintrc config:

{
  "plugins": ["import"],
  "rules": {
    // turn on errors for missing imports
    "import/no-unresolved": "error"
  },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "typescript": {
        "alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

        // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default

        // use <root>/path/to/folder/tsconfig.json
        "project": "path/to/folder",

        // Multiple tsconfigs (Useful for monorepos)

        // use a glob pattern
        "project": "packages/*/tsconfig.json",

        // use an array
        "project": [
          "packages/module-a/tsconfig.json",
          "packages/module-b/tsconfig.json"
        ],

        // use an array of glob patterns
        "project": [
          "packages/*/tsconfig.json",
          "other-packages/*/tsconfig.json"
        ]
      }
    }
  }
}

Options from enhanced-resolve

conditionNames

Default:

[
  "types",
  "import",

  // APF: https://angular.io/guide/angular-package-format
  "esm2020",
  "es2020",
  "es2015",

  "require",
  "node",
  "node-addons",
  "browser",
  "default"
]

extensions

Default:

[
  // `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly
  ".ts",
  ".tsx",
  ".d.ts",
  ".js",
  ".jsx",
  ".json",
  ".node"
]

extensionAlias

Default:

{
  ".js": [
    ".ts",
    // `.tsx` can also be compiled as `.js`
    ".tsx",
    ".d.ts",
    ".js"
  ],
  ".jsx": [".tsx", ".d.ts", ".jsx"],
  ".cjs": [".cts", ".d.cts", ".cjs"],
  ".mjs": [".mts", ".d.mts", ".mjs"]
}

mainFields

Default:

[
  "types",
  "typings",

  // APF: https://angular.io/guide/angular-package-format
  "fesm2020",
  "fesm2015",
  "esm2020",
  "es2020",

  "module",
  "jsnext:main",

  "main"
]

Other options

You can pass through other options of enhanced-resolve directly

Default options

You can reuse defaultConditionNames, defaultExtensions, defaultExtensionAlias and defaultMainFields by require/import them directly

Contributing

  • Make sure your change is covered by a test import.
  • Make sure that yarn test passes without a failure.
  • Make sure that yarn lint passes without conflicts.
  • Make sure your code changes match our type-coverage settings: yarn type-coverage.

We have GitHub Actions which will run the above commands on your PRs.

If either fails, we won't be able to merge your PR until it's fixed.

Sponsors

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Backers

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

ISC

eslint-plugin-import

Used in package.json
Author: Ben Mosher Description: Import with sanity.
License: MIT Homepage: https://github.com/import-js/eslint-plugin-import
Keywords: eslint, eslintplugin, eslint-plugin, es6, jsnext, modules, import and export
Updated: 2 months ago Created: almost 9 years ago
Releases: 129 Maintainers: 3
Direct Dependencies: array-includes, array.prototype.findlastindex, array.prototype.flat, array.prototype.flatmap, debug, doctrine, eslint-import-resolver-node, eslint-module-utils, hasown, is-core-module, is-glob, minimatch, object.fromentries, object.groupby, object.values, semver, tsconfig-paths
This README is too long to show.

Generated by 🚫 dangerJS against 44ea34f

@alice-byb alice-byb merged commit b56fd61 into main Feb 27, 2024
10 checks passed
@alice-byb alice-byb deleted the task/add-import-eslint-rules branch February 27, 2024 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants