Skip to content
GitHub

ESLint

Lint and format JS, TS, Vue, JSON, YAML and Markdown with @ueberbit/eslint-config.

@ueberbit/eslint-config is based on @antfu/eslint-config. It lints and formats JS, TS, Vue, JSON, YAML and Markdown without Prettier: single quotes, no semicolons, dangling commas and sorted imports. Drupal globals are added automatically.

Install

pnpm add -D @ueberbit/eslint-config

Configure

eslint.config.js
import config from '@ueberbit/eslint-config'

export default config()

config() takes all options of @antfu/eslint-config and any number of extra flat config items:

eslint.config.js
import config from '@ueberbit/eslint-config'

export default config({
  vue: true,
}, {
  files: ['js/**/*.js'],
  rules: {
    'no-console': 'off',
  },
})

Add a script to the package.json:

package.json
{
  "scripts": {
    "lint": "eslint . --cache",
    "lint:fix": "eslint . --cache --fix"
  }
}

--cache only lints changed files again. Add .eslintcache to your .gitignore.

Ignored files

All files ignored by Git are skipped. Unlike plain @antfu/eslint-config, the .gitignore files in parent directories up to the repository root are applied as well, so a theme inside a Drupal project respects the project's .gitignore.

These are ignored on top of that:

Pattern Why
**/tsconfig.json, .vscode/** Comments and trailing commas are allowed there.
**/composer.json, **/composer.lock Formatted by Composer.
**/.storybook/**, **/*.stories.jsx Legacy Storybook files.
**/_deprecated/** Code that is about to be removed.
**/.uebertool/** Generated by the Vite plugin.

Pass ignores to add patterns, un-ignore with !pattern or pass a function to replace the list:

eslint.config.js
export default config({
  ignores: ['legacy/**', '!**/composer.json'],
})

Drupal

@ueberbit/eslint-config-drupal is included. It applies to js, ts and vue files when the current directory is a Drupal project (a composer.json that requires a drupal/* package) or a Drupal theme or module (a *.info.yml). It adds these read-only globals:

Drupal, drupalSettings, drupalTranslations, once, jQuery, _, Cookies, Backbone, Modernizr, loadjs, Popper, Shepherd, Sortable, CKEDITOR, CKEditor5, tabbable.