https://github.com/perfective/eslint-config
A shareable ESLint configuration for the development of Perfective TypeScript packages
https://github.com/perfective/eslint-config
code-quality code-style eslint eslint-config lint typescript
Last synced: 2 months ago
JSON representation
A shareable ESLint configuration for the development of Perfective TypeScript packages
- Host: GitHub
- URL: https://github.com/perfective/eslint-config
- Owner: perfective
- License: mit
- Created: 2021-01-05T08:10:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-24T16:14:18.000Z (about 1 year ago)
- Last Synced: 2024-04-25T18:43:06.745Z (about 1 year ago)
- Topics: code-quality, code-style, eslint, eslint-config, lint, typescript
- Language: TypeScript
- Homepage:
- Size: 4.54 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.adoc
- Changelog: CHANGELOG.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Perfective ESLint Config
`@perfective/eslint-config` provides
a https://eslint.org/docs/latest/developer-guide/shareable-configs[shareable ESLint configuration]
that is used for the development of the `@perfective` packages.
These rules are primarily configured for TypeScript projects.In addition to the core https://eslint.org/docs/latest/rules/[ESLint],
`link:https://typescript-eslint.io/rules/[@typescript-eslint]`,
and https://eslint.style[ESLint Stylistic] plugin rules,
`@perfective/eslint-config` includes configurations for the ESLint plugins:* `link:https://github.com/freaktechnik/eslint-plugin-array-func[eslint-plugin-array-func]`;
* `link:https://github.com/cypress-io/eslint-plugin-cypress[eslint-plugin-cypress]` _(optional)_;
* `link:https://mysticatea.github.io/eslint-plugin-eslint-comments/[eslint-plugin-eslint-comments]`;
* `link:https://github.com/import-js/eslint-plugin-import[eslint-plugin-import]`;
* `link:https://github.com/jest-community/eslint-plugin-jest[eslint-plugin-jest]` _(optional)_;
* `link:https://github.com/testing-library/eslint-plugin-jest-dom[eslint-plugin-jest-dom]` _(optional)_;
* `link:https://github.com/gajus/eslint-plugin-jsdoc[eslint-plugin-jsdoc]`;
* `link:https://github.com/eslint-community/eslint-plugin-n[eslint-plugin-n]`;
* `link:https://github.com/TristonJ/eslint-plugin-prefer-arrow[eslint-plugin-prefer-arrow]`;
* `link:https://github.com/eslint-community/eslint-plugin-promise[eslint-plugin-promise]`;
* `link:https://github.com/cartant/eslint-plugin-rxjs[eslint-plugin-rxjs]` _(optional)_;
* `link:https://github.com/eslint-community/eslint-plugin-security[eslint-plugin-security]`;
* `link:https://github.com/lydell/eslint-plugin-simple-import-sort[eslint-plugin-simple-import-sort]`;
* `link:https://github.com/testing-library/eslint-plugin-testing-library[eslint-plugin-testing-library]` _(optional)_;
* `link:https://github.com/sindresorhus/eslint-plugin-unicorn[eslint-plugin-unicorn]`.To simplify configuring ESLint support in the IDEs and editors,
the severity of all fixable rules is a `warning`.
In addition, it allows distinguishing errors that have to be fixed manually
from issues that will be fixed automatically.== Setup
. Require `@perfective/eslint-config` and its peer dependencies as dev dependencies
+
[source,bash]
----
npm install --save-dev \
@perfective/eslint-config \
@stylistic/eslint-plugin \
@stylistic/eslint-plugin-js \
@stylistic/eslint-plugin-jsx \
@stylistic/eslint-plugin-ts \
@stylistic/eslint-plugin-plus \
eslint \
eslint-import-resolver-typescript \
eslint-plugin-array-func \
eslint-plugin-eslint-comments \
eslint-plugin-import \
eslint-plugin-jsdoc \
eslint-plugin-n \
eslint-plugin-prefer-arrow \
eslint-plugin-promise \
eslint-plugin-security \
eslint-plugin-simple-import-sort \
eslint-plugin-unicorn \
typescript-eslint
----
+
. Require the configuration in your root `eslint.config.js`.
+
[source,javascript]
----
const perfectiveEslintConfig = require('@perfective/eslint-config');module.exports = perfectiveEslintConfig.default;
----
+
. `*.d.ts` files and `dist` directories are ignored by the configuration.
`node_modules` and dot-files are ignored by the `eslint`.
If more directories or file types need to be ignored, see the
`link:https://eslint.org/docs/user-guide/configuring/ignoring-code#the-eslintignore-file[.eslintignore]` file docs.
+
. Install optional peer dependencies that add linting rules for the tools you use.
+
[source,bash]
----
npm install --save-dev \
@smarttools/eslint-plugin-rxjs \
eslint-plugin-cypress \
eslint-plugin-jest \
eslint-plugin-jest-dom \
eslint-plugin-testing-library
----
+
. Add optional configurations to your root `eslint.config.js`.
+
[source,javascript]
----
import perfectiveEslintConfig from '@perfective/eslint-config';// Optional dependencies.
import { cypressConfig } from '@perfective/eslint-config/cypress';
import { jestConfig } from '@perfective/eslint-config/jest';
import { jestDomConfig } from '@perfective/eslint-config/jest-dom';
import { rxjsConfig } from '@perfective/eslint-config/rxjs';
import { testingLibraryConfig } from '@perfective/eslint-config/testing-library';const eslintConfig = [
...perfectiveEslintConfig,
cypressConfig(),
jestConfig(),
jestDomConfig(),
rxjsConfig(),
testingLibraryConfig(),
];export default eslintConfig;
----== Rules Configuration Extension Functions
Some rules have complex configuration objects or arrays
that are not merged but are completely overridden by ESLint.
Therefore, it requires copying and pasting a rule config instead of just extending it.
Maintaining rules updates is challenging
and is simplified by the custom config functions.These functions and related types are exported in `@perfective/eslint-config/rules`
and match the rule name in `camelCase`.
If you need an extended configuration,
you can use these functions in the `eslint.config.js` file:[source,javascript]
----
import perfectiveEslintConfig from '@perfective/eslint-config';
import { simpleImportSortImports } from '@perfective/eslint-config/rules'; // <.>const eslintConfig = [
...perfectiveEslintConfig,
{
files: ['**/*.[jt]s?(x)'],
rules: {
'simple-import-sort/imports': ['warn', rules.simpleImportSortImports([
'@perfective',
])],
},
},
];export default eslintConfig;
----
<1> Framework-specific packages, based on `@perfective/eslint-config`, re-export all the rules.
So rules should be required from those packages for correct `node_modules` resolution.=== Supported Rules
* `simpleImportSortImports(internal)`
— allows to splice `internal` scope packages imports sorting
for the `simple-import-sort/imports` rule.
* `typescriptEslintNamingConvention(extensions)`
— extends configuration for the `@typescript-eslint/naming-convention` rule.
* `unicornPreventAbbreviations(replacements, options)`
— extends and overrides the list of `replacements`
and `options` for the `unicorn/prevent-abbreviation` rule.