1.0.3 • Published 6 months ago

@chuhoman/eslint-config v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@chuhoman/eslint-config

npm

!IMPORTANT Since v1.0.0, this config is rewritten to the new ESLint Flat config.

Usage

Install

# pnpm
pnpm install -D eslint @chuhoman/eslint-config

Create config file

With "type": "module" in package.json (recommended):

// eslint.config.js
import chuhoman from '@chuhoman/eslint-config';

export default chuhoman();

With CJS:

// eslint.config.js
const chuhoman = require('@chuhoman/eslint-config').default;

module.exports = chuhoman();

Add script for package.json

For example:

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
  }
}

Config VS Code

Install VS Code ESLint extension and create .vscode/settings.json

{
  "prettier.enable": false,
  // Enable the ESlint flat config support
  "eslint.experimental.useFlatConfig": true,

  // Disable the default formatter, use eslint instead
  "editor.formatOnSave": false,

  // Auto fix
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.organizeImports": false
  },

  // Silent the stylistic rules in you IDE, but still auto fix them
  "eslint.rules.customizations": [
    { "rule": "style/*", "severity": "off" },
    { "rule": "*-indent", "severity": "off" },
    { "rule": "*-spacing", "severity": "off" },
    { "rule": "*-spaces", "severity": "off" },
    { "rule": "*-order", "severity": "off" },
    { "rule": "*-dangle", "severity": "off" },
    { "rule": "*-newline", "severity": "off" },
    { "rule": "*quotes", "severity": "off" },
    { "rule": "*semi", "severity": "off" }
  ],

  // Enable eslint for all supported languages
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "vue",
    "html",
    "markdown",
    "json",
    "jsonc",
    "yaml"
  ]
}

Customization

you can configure each integration individually, for example:

// eslint.config.js
import chuhoman from '@chuhoman/eslint-config';

export default chuhoman(
  {
  // Enable stylistic formatting rules
  // stylistic: true,

    // Or customize the stylistic rules
    stylistic: {
      indent: 2, // 4, or 'tab'
      quotes: 'single', // or 'double'
    },

    // TypeScript and Vue are auto-detected, you can also explicitly enable them:
    typescript: true,
    vue: true,

    // Disable jsonc and yaml support
    jsonc: false,
    yaml: false,

    // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
    ignores: [
      './fixtures',
    // ...globs
    ]
  },
  // From the second arguments they are ESLint Flat Configs
  // you can have multiple configs
  {
    files: ['**/*.ts'],
    rules: {},
  },
  {
    rules: {},
  },
);

Credits

Inspired by

License

Made with 💙

Published under MIT License.