Gathering detailed insights and metrics for @wayofdev/eslint-config-bases
Gathering detailed insights and metrics for @wayofdev/eslint-config-bases
Shareable configurations with fully automated package publishing to NPM Registry.
npm install @wayofdev/eslint-config-bases
Typescript
Module System
Node Version
NPM Version
@wayofdev/tsconfig-config@4.0.0
Updated on Jan 11, 2024
@wayofdev/stylelint-config@4.0.0
Updated on Jan 11, 2024
@wayofdev/secretlint-config@4.0.0
Updated on Jan 11, 2024
@wayofdev/postcss-config@4.0.0
Updated on Jan 11, 2024
@wayofdev/markdownlint-config@4.0.0
Updated on Jan 11, 2024
@wayofdev/htmlhint-config@4.0.0
Updated on Jan 11, 2024
JavaScript (89.36%)
Makefile (9.37%)
Shell (1.27%)
Love this project? Help keep it running โ sponsor us today! ๐
Total Downloads
31,079
Last Day
22
Last Week
222
Last Month
1,788
Last Year
17,302
MIT License
12 Stars
931 Commits
1 Forks
1 Watchers
17 Branches
3 Contributors
Updated on Oct 26, 2024
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
@wayofdev/eslint-config-bases@4.0.0
Unpacked Size
54.35 kB
Size
14.01 kB
File Count
31
NPM Version
10.2.3
Node Version
20.10.0
Published on
Jan 11, 2024
Cumulative downloads
Total Downloads
Last Day
-52.2%
22
Compared to previous day
Last Week
-55.2%
222
Compared to previous week
Last Month
-5.9%
1,788
Compared to previous month
Last Year
26.7%
17,302
Compared to previous year
28
9
Composable eslint config bases for wayofdev projects and others.
The purpose of the package is to provide composable and monorepo friendly eslint configurations for JavaScript based projects. It includes features such as performance optimization and the ability to extend pre-defined base configs.
To install @wayofdev/eslint-config-bases
, add it as a dev-dependency to your monorepo workspaces and in your root package.json
:
1# Install as dev-dependency into monorepo root 2$ pnpm add -wD \ 3 @wayofdev/eslint-config-bases \ 4 npm-run-all 5 6# Install as dev-dependency per workspace (app or package) 7$ pnpm --filter=my-first-app add -D @wayofdev/eslint-config-bases 8$ pnpm --filter=my-first-package add -D @wayofdev/eslint-config-bases
Assuming that you have the following structure:
1. 2โโโ package.json (root) 3โโโ apps 4โ โโโ my-first-app 5โ โโโ package.json 6โ โโโ ... (other app files) 7โโโ packages 8 โโโ my-first-package 9 โโโ package.json 10 โโโ ... (other package files)
PS: if you use graphql rules, add the
@graphql-eslint/eslint-plugin
as well (not done by default as it comes with many transitive deps you might not need)
Here are some example scripts you can add to your root package.json
:
1# Runs md, js and secrets linters 2$ pnpm pkg set scripts.lint="run-p lint:turbo lint:md lint:html lint:css lint:secrets lint:package-json" 3 4# Runs lint command using turbo (affects all */packages) with auto-fix and sorts package.json after 5$ pnpm pkg set scripts.lint:fix="turbo run lint:fix && pnpm lint:package-json" 6 7# Runs lint only on *.md files 8$ pnpm pkg set scripts.lint:md="markdownlint --fix **/*.md --ignore '**/node_modules/**' --ignore '**/CHANGELOG.md'" 9 10# Sorts package.json in project 11$ pnpm pkg set scripts.lint:package-json="sort-package-json package.json apps/*/package.json packages/*/package.json" 12 13# Searches only for secrets 14$ pnpm pkg set scripts.lint:secrets="secretlint **/*" 15 16# Runs lint command over all packages using turbopack 17$ pnpm pkg set scripts.lint:turbo="turbo lint"
You can also manually add commands to your workspaces, located in apps/*
and packages/*
. For example:
1{ 2 "scripts": { 3 "lint": "eslint --ext .ts,.js,.cjs,.mjs --cache --cache-location ../../.cache/eslint/eslint-config-bases.eslintcache", 4 "lint:fix": "eslint --ext .ts,.tsx,.js,.jsx,.mjs,.cjs,.mts,.cts --fix --cache --cache-location ../../.cache/eslint/eslint-config-bases.eslintcache" 5 } 6}
To create your workspace-specific ESLint configuration, create a file ./apps/my-first-app/.eslintrc.js
or ./apps/my-first-app/.eslintrc.cjs
that extends any of the existing base configs.
For example, if you have a Next.js application, your .eslintrc.js
would look something like this:
1// Next line only required if you're using a monorepo 2// Workaround for https://github.com/eslint/eslint/issues/3458 (re-export of @rushstack/eslint-patch) 3require("@wayofdev/eslint-config-bases/patch/modern-module-resolution"); 4 5module.exports = { 6 root: true, 7 parserOptions: { 8 tsconfigRootDir: __dirname, 9 project: 'tsconfig.json', 10 }, 11 ignorePatterns: [...getDefaultIgnorePatterns(), '.next', '.out', '/storybook-static'], 12 extends: [ 13 '@wayofdev/eslint-config-bases/typescript', 14 '@wayofdev/eslint-config-bases/regexp', 15 '@wayofdev/eslint-config-bases/sonar', 16 '@wayofdev/eslint-config-bases/jest', 17 '@wayofdev/eslint-config-bases/rtl', 18 '@wayofdev/eslint-config-bases/react', 19 '@wayofdev/eslint-config-bases/react-query, 20 '@wayofdev/eslint-config-bases/tailwind', 21 '@wayofdev/eslint-config-bases/mdx', 22 // '@wayofdev/eslint-config-bases/graphql-schema', 23 // '@wayofdev/eslint-config-bases/storybook', 24 // '@wayofdev/eslint-config-bases/playwright', 25 26 // Add specific rules for your framework if needed. 27 // ie: 28 'plugin:@next/next/core-web-vitals', 29 // '@remix-run/eslint-config', 30 // ... 31 32 // Post configure the prettier base and run prettier 33 // without conflicts thx to eslint-plugin-prettier 34 "@wayofdev/eslint-config-bases/prettier-plugin", 35 // Alternatively to the above if you're already running prettier 36 // we can get a speed up by using on eslint-prettier-config 37 // "@wayofdev/eslint-config-bases/prettier-config", 38 ], 39 rules: { 40 // Specific global rules for your app or package 41 // https://github.com/vercel/next.js/discussions/16832 42 '@next/next/no-img-element': 'off', 43 // For the sake of example 44 // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md 45 'jsx-a11y/anchor-is-valid': 'off', 46 '@typescript-eslint/no-unused-vars': 'off', 47 }, 48 overrides: [ 49 // Specific file rules for your app or package 50 { 51 files: ['src/pages/\\_*.{ts,tsx}'], 52 rules: { 53 'react/display-name': 'off', 54 }, 55 }, 56 { 57 files: ['src/stories/*.ts'], 58 rules: { 59 '@typescript-eslint/naming-convention': 'off', 60 }, 61 }, 62 ], 63}
Tip:
Prettier:
@wayofdev/eslint-config-bases/prettier-plugin
and@wayofdev/eslint-config-bases/prettier-config
are mutually exclusives. Choose one. Theprettier-config
suppose that you run prettier independently. Theprettier-plugin
will run prettier for you. Easiest theprettier-plugin
, fastestprettier-config
(this mostly depends if you set up and persist caches as well)Performance: Some rules are known to be slow (ie:
import/namespace
...). Slowest identified rules are disabled depending on context (ie:*.test.tsx?
might not need everything). Depending on project it's possible to disable entirely some slow rules (ie:'import/namespace': 'off'
). A good tip run eslint with theTIMING=1
to identify slow rules.
You can find the bases in ./src/bases.
Base | Match convention | Scope |
---|---|---|
typescript | all | Naming conventions, consistent imports, import sorting... |
sonar | *.{js,jsx,ts,tsx} | Keep levels of code complexity sane. (excl test and stories) |
regexp | *.{js,jsx,jsx,tsx} | Keep regexp consistent and safer. |
react | *.{jsx,tsx} | Recommendations for react, react-hooks and jsx projects. |
react-query | **/?(*.)+(test).{js,jsx,ts,tsx} | Enforce "recommended" react-query usage. |
jest | **/?(*.)+(test).{js,jsx,ts,tsx} | Catch inconsistencies or error in jest tests. |
rtl | **/?(*.)+(test).{js,jsx,ts,tsx} | Potential errors / deprecations in react-testing-library tests. |
graphql-schema | *.graphql | Ensure validity of graphql schema files. |
storybook | *.stories.{ts,tsx,mdx} | Potential errors / deprecations in stories. |
playwright | **/e2e/**/*.test.{js,ts} | Keep "recommended" playwright usage. |
prettier-plugin | all | Post configure eslint for prettier compatibility. |
Notes:
The order is important. Some bases will disable or tune previously defined rules. For example the react base will tune the naming conventions for function components and increase recommended cognitive complexity. The typescript base will also relax conventions for javascript files.
Based on filename conventions some rules are relaxed or disabled to avoid false positives and keep a good level of performance. For example the sonar base won't run on test and storybook files. If you work on different conventions the patterns must be updated.
Two ways to work with prettier.
@wayofdev/eslint-config-bases/prettier-plugin
โ eslint will run prettier under the hood (default)@wayofdev/eslint-config-bases/prettier-config
โ eslint will just disable some conflicting rules (so you'll need to run prettier after)The first method is recommended for simplicity. For best perf use the cache option to run eslint.
Tune the behaviour by creating a config, named .prettierrc.js
in root directory of project and in each package or app.
1. 2โโโ .prettierrc.js (root) 3โโโ package.json (root) 4โโโ apps 5โ โโโ my-first-app 6โ โโโ .prettierrc.js 7โ โโโ package.json 8โ โโโ ... (other app files) 9โโโ packages 10 โโโ my-first-package 11 โโโ .prettierrc.js 12 โโโ package.json 13 โโโ ... (other package files)
.prettierrc.js
for root of monorepo:1// @ts-check 2 3const { getPrettierConfig } = require('@wayofdev/eslint-config-bases/helpers') 4const { overrides = [], ...prettierConfig } = getPrettierConfig() 5 6/** 7 * @type {import('prettier').Config} 8 */ 9module.exports = { 10 ...prettierConfig, 11 overrides: [ 12 ...overrides, 13 ...[ 14 { 15 files: '*.md', 16 options: { 17 singleQuote: false, 18 quoteProps: 'preserve', 19 }, 20 }, 21 ], 22 ], 23}
Tip: You can tune the provided prettier.base.config for your own needs.
Generic typescript project, mostly based on
Type/Plugin | Comment |
---|---|
eslint:recommended | The basics for code linting. |
@typescript-eslint/recommended | The basics for typescript. |
@typescript-eslint/consistent-type | Use TS 3.8+ imports/exports, helps with esbuild |
@typescript-eslint/naming-convention | |
eslint-plugin-import | Order imports |
Type/Plugin | Comment |
---|---|
eslint-plugin-sonarjs/recommended | Help to keep complexity sane |
Type/Plugin | Comment |
---|---|
eslint-plugin-react/recommended | |
eslint-plugin-react-hooks/recommended | |
eslint-plugin-jsx-a11y/recommended | Helps to produce accessibility-ready jsx |
Type/Plugin | Comment |
---|---|
eslint-plugin-jest/recommended | Jest recommended practices. |
Type/Plugin | Comment |
---|---|
eslint-plugin-testing-library/recommended | Ease when using react-testing-library |
Type/Plugin | Comment |
---|---|
eslint-plugin-regexp/recommended | ESLint plugin for finding regex mistakes and style guide violations. |
Type/Plugin | Comment |
---|---|
mdx-js/eslint-mdx | ESLint Parser/Plugin for MDX, helps you lint all ES syntaxes. |
Type/Plugin | Comment |
---|---|
html-eslint/recommended | ESLint plugin for linting HTML |
Based on:
This repository was created in 2023 by lotyp / wayofdev.
Thank you for considering contributing to the wayofdev community! We are open to all kinds of contributions. If you want to:
You are more than welcome. Before contributing, kindly check our guidelines.
No vulnerabilities found.
No security vulnerabilities found.