Détail du package

@tiagoporto/eslint-config

tiagoporto364MIT4.7.0

Shareable Config for ESlint.

eslint, shareable, config

readme

@tiagoporto/eslint-config

Shareable Config for ESlint.

Installation

npm install --save-dev eslint globals @tiagoporto/eslint-config

Usage

Browser

// eslint.config.mjs
import globals from 'globals'

/** @type {import('eslint').Linter.Config[]} */
export default [
  {
    languageOptions: { globals: globals.browser }
  }
]

Node

// eslint.config.mjs
import globals from 'globals'

/** @type {import('eslint').Linter.Config[]} */
export default [{ languageOptions: { globals: globals.node } }]

configs

base

Linted files

  • HTML - html and code into script tag
  • YAML - yml, and yaml
  • Json - json, jsonc and json5
  • Markdown - md, markdown, mdx and code blocks
  • Javascript - js,mjs and cjs
  • Typescript - ts,mts and cts
// eslint.config.mjs
import tpConfig from '@tiagoporto/eslint-config'

/** @type {import('eslint').Linter.Config[]} */
export default [...tpConfig.configs.base]

react

Linted files

All from base config plus JavaScript XML - jsx and tsx

// eslint.config.mjs
import tpConfig from '@tiagoporto/eslint-config'

/** @type {import('eslint').Linter.Config[]} */
export default [...tpConfig.configs.react]

In package.json add the following scripts:

{
  "scripts": {
    "lint": "eslint --max-warnings 0",
    "lint:fix": "npm run lint -- --write"
  }
}

Lint-staged

Check staged files

// .lintstagedrc.mjs
export default {
  '*.{md,markdown,mdx}': [
    // remark,
    'eslint --max-warnings 0 --no-warn-ignored'
  ],
  '*.{html,yml,json,jsonc,json5}': 'eslint --max-warnings 0 --no-warn-ignored',
  '*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}': [
    'eslint --max-warnings 0 --no-warn-ignored'
    // unit test
  ]
}

Editor

For VSCode is recommended the following extensions:

// .vscode/settings.json
{
  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit"
  },
  "editor.formatOnSave": true,
  "eslint.validate": ["yaml", "github-actions-workflow"]
}