3.0.4 • Published 6 months ago

@kouts/eslint-config v3.0.4

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

@kouts/eslint-config

Custom ESLint and Prettier config with Vue.js support and sensible defaults

!NOTE
Starting from v1, this ESLint config uses the ESLint Flat config and is only compatible with ESLint v9 or v8.50.0+.
If you're looking for the previous version, checkout the README here.

Installation

pnpm i -D @kouts/eslint-config eslint prettier

Usage

ESLint config

Add an eslint.config.js (or eslint.config.cjs if your project is CommonJS) that imports the config function:

import { config } from '@kouts/eslint-config'

export default [
  ...config({
    env: ['browser'], // Add your environment globals here
  }),
  {
    // Add custom rules here
  },
]

Customizing the config

The configuration comes with default settings that extend the neostandard config. You can further customize it by passing an object to the config function:

Config settings defaults:

OptionTypeDescriptionDefault
tsbooleanEnable TypeScript supporttrue
noJsxbooleanNo jsx rules will be addedtrue
noStylebooleanNo style rules will be addedtrue
semibooleanUse semicolonsfalse
vuebooleanEnable Vue.js supporttrue
vueVersion2 or 3Specify the version of Vue.js3
vitestbooleanEnable Vitest supporttrue

Example:

config({
  ts: false,
  vue: true
  vueVersion: 3,
  vitest: false,
})

Prettier config

Create a prettier.config.js file with the following content:

import prettierConfig from '@kouts/eslint-config/prettier'

export default prettierConfig

package.json scripts

Add the following ESLint commands to your .package-json for linting and autofixing:

{
  "lint": "eslint \"**/*.{vue,ts,js}\"",
  "lint-fix": "eslint --fix \"**/*.{vue,ts,js}\""
}

VS Code settings

Ad the following settings to your VS Code project settings for autofix on save:

.vscode/settings.json

{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Features

Vue-specific Rules

This configuration extends the ESLint plugin Vue recommended preset but makes several modifications to enhance code quality and consistency in Vue components.

Disabled Rules

  • vue/max-attributes-per-line: Turned off to allow flexibility in attribute formatting
  • vue/singleline-html-element-content-newline: Turned off for cleaner code with fewer line breaks

Strengthened Rules (set to 'error')

  • vue/attributes-order: Enforces consistent order of component attributes
  • vue/block-order: Enforces consistent order of component blocks
  • vue/no-lone-template: Prevents unnecessary template wrappers
  • vue/no-multiple-slot-args: Prevents passing multiple arguments to slots
  • vue/no-v-html: Prevents use of v-html to mitigate XSS risks
  • vue/order-in-components: Enforces consistent order of component options
  • vue/this-in-template: Prevents usage of this in templates
  • vue/require-prop-types: Requires type definitions for props
  • vue/component-name-in-template-casing: Enforces PascalCase for component names in templates
  • vue/no-static-inline-styles: Prevents inline styles in templates
  • vue/require-explicit-emits: Requires explicit emit declarations
  • vue/require-name-property: Requires components to have a name property
  • vue/html-self-closing: Enforces self-closing style for components with no content
  • vue/dot-notation: Enforces dot notation where possible in templates

Custom Vue Rules

  • kouts/vue-require-name-in-setup: Enforces that Vue components using <script setup> must have a component name.

Customizing/Disabling Vue Rules

You can customize or disable any of these rules in your ESLint config:

// eslint.config.js
import { config } from '@kouts/eslint-config'

export default [
  ...config(),
  {
    rules: {
      // Disable custom rule
      'kouts/vue-require-name-in-setup': 'off',

      // Modify strengthened Vue rules
      'vue/attributes-order': 'warn',
      'vue/no-v-html': 'off',

      // Re-enable rules that were turned off
      'vue/max-attributes-per-line': [
        'error',
        {
          singleline: { max: 3 },
          multiline: { max: 1 },
        },
      ],
    },
  },
]

License

MIT

2.0.3

10 months ago

2.0.2

10 months ago

2.0.5

9 months ago

2.0.4

9 months ago

2.0.7

8 months ago

2.0.6

9 months ago

2.0.8

8 months ago

2.0.1

10 months ago

2.0.0

10 months ago

3.0.4

6 months ago

3.0.3

6 months ago

3.0.2

6 months ago

1.3.19

12 months ago

3.0.1

7 months ago

3.0.0

7 months ago

1.3.20

12 months ago

1.3.21

12 months ago

1.3.22

11 months ago

1.3.23

11 months ago

1.3.18

12 months ago

1.3.17

12 months ago

1.3.16

1 year ago

1.3.14

1 year ago

1.3.15

1 year ago

1.3.13

1 year ago

1.3.12

1 year ago

1.3.11

1 year ago

1.3.10

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

0.0.15

1 year ago

0.0.14

2 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago