@toyokumo/eslint-config

2.1.2 • Public • Published

eslint-config

npm version Test

A ESLint rule set for Toyokumo.

Purpose

  • Standardization of coding style.
  • Installation and setting support for ESLint.

Use prettier for code format

  • All rules provided by toyokumo/eslint-config assume the use of prettier.
  • Use prettier-config-plugin to avoid lint errors where it overlaps with prettier format rules.
    • If we find a red squiggly line, we will want to fix it, but we don't have to manually fix what we can fix by formatting
  • For the lint + format method, refer to the method of this repository.
  • This policy might be changed.

Usage

npm i --save-dev @toyokumo/eslint-config eslint @toyokumo/prettier-config prettier npm-run-all
# or
yarn add --dev @toyokumo/eslint-config eslint @toyokumo/prettier-config prettier npm-run-all

Setup npm scripts

We must use prettier for code format when using @toyokumo/eslint-config.

We are taking this strategy for code format - eslint --fix -> prettier --write

An Example of npm scripts to achieve this strategy.

{
  "scripts": {
    "format": "run-s \"format:eslint -- {1}\" \"format:prettier -- {1}\" --",
    "format:eslint": "eslint --fix",
    "format:prettier": "prettier --write",
    "format-all": "npm run format \"./**/*.{js,ts,tsx}\"",
    "format-all:eslint": "eslint --fix \"./**/*.{js,ts,tsx}\"",
    "format-all:prettier": "prettier --write \"./**/*.{js,ts,tsx}\""
  }
}

Configuration object

const toyokumoEslint = require('@toyokumo/eslint-config');
/* 
Imported toyokumoEslint is a object of ESLint configurations.

{
  // config is a config helper function inspired by typescript-eslint.
  // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/src/config-helper.ts
  config,
  // configs is a object of ESLint configurations.
  configs: {
    base, // Linter.FlatConfig[]
    js, // Linter.FlatConfig[]
    ts, // Linter.FlatConfig[]
    tsx, // Linter.FlatConfig[]
    react, // Linter.FlatConfig[]
    next, // Linter.FlatConfig[]
    tailwindcss, // Linter.FlatConfig[]
    jest, // Linter.FlatConfig[]
    prettier, // Linter.FlatConfig[]
  },
}

 */

Setup eslint.config.js

We just set the ideal rule set, so we can overwrite or ignore the rule depending on the project situation.

// Most simple example
const toyokumoEslint = require('@toyokumo/eslint-config');

module.exports = [
  ...toyokumoEslint.configs.base,
  ...toyokumoEslint.configs.js,
  ...toyokumoEslint.configs.ts,
  ...toyokumoEslint.configs.tsx,
  ...toyokumoEslint.configs.react,
  ...toyokumoEslint.configs.next,
  ...toyokumoEslint.configs.tailwindcss,
  ...toyokumoEslint.configs.prettier,
  {
    rules: {
      // Overwrite my rule
    }
  },
];

// Multi modules
module.exports = [
  ...toyokumoEslint.configs.base,
  ...toyokumoEslint.configs.tsx, // *.tsx only.
  ...toyokumoEslint.config({
    files: ['packages/next/**/*.ts', 'packages/next/**/*.tsx'],
    extends: [
      ...toyokumoEslint.configs.ts,
      ...toyokumoEslint.configs.react,
      ...toyokumoEslint.configs.next,
      ...toyokumoEslint.configs.tailwindcss,
      {
        languageOptions: {
          parserOptions: {
            project: 'packages/next/tsconfig.json',
          },
        },
        settings: {
          'import/resolver': {
            typescript: {
              project: 'packages/next/tsconfig.json',
            },
          },
          tailwindcss: {
            config: 'packages/next/tailwind.config.ts',
          },
        },
      }
    ],
    rules: {
      '@next/next/no-html-link-for-pages': ['error', 'packages/next/app'],
      // Overwrite my rule
    }
  }),
  ...toyokumoEslint.config({
    files: ['packages/ui-component/**/*.ts', 'packages/ui-component/**/*.tsx'],
    extends: [
      ...toyokumoEslint.configs.ts,
      ...toyokumoEslint.configs.react,
      ...toyokumoEslint.configs.tailwindcss,
      {
        languageOptions: {
          parserOptions: {
            project: 'packages/ui-component/tsconfig.json',
          },
        },
        settings: {
          'import/resolver': {
            typescript: {
              project: 'packages/ui-component/tsconfig.json',
            },
          },
          tailwindcss: {
            config: 'packages/ui-component/tailwind.config.ts',
          },
        },
      }
    ],
    rules: {
      // Overwrite my rule
    }
  }),
  ...toyokumoEslint.configs.prettier,
];

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.1.233latest

Version History

VersionDownloads (Last 7 Days)Published
2.1.233
2.1.11
2.1.01
2.0.141
2.0.1326
2.0.120
2.0.110
2.0.100
2.0.90
2.0.80
2.0.70
2.0.60
2.0.50
2.0.40
2.0.30
2.0.20
2.0.10
1.1.627
1.1.50
1.1.40
1.1.20
1.1.10
1.1.00
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.61
1.0.50
1.0.40
1.0.31
1.0.20
1.0.11
1.0.00

Package Sidebar

Install

npm i @toyokumo/eslint-config

Weekly Downloads

92

Version

2.1.2

License

MIT

Unpacked Size

19.9 kB

Total Files

15

Last publish

Collaborators

  • toyokumo