EveryPage

Unofficial example

Ask the ESLint docs

The Ask this site box, reading eslint.org/docs/latest. Type a question and it answers from those pages, with links.

Loading the box…

An unofficial example. Ask this site is not affiliated with or endorsed by the ESLint project. The ESLint docs belong to their authors and are read here under their MIT licence.

Questions it answered

Real answers from this box.

  • How do I disable a rule for one line?

    To disable a specific rule on a single line, use a line or block comment naming the rule. Any of these forms works:

    • Trailing line comment: put // eslint-disable-line no-alert after the code on the same line.
    • Next-line comment: put // eslint-disable-next-line no-alert on the line above the code.
    • Block comment forms: /* eslint-disable-line no-alert */ after the code, or /* eslint-disable-next-line no-alert */ before it.

    To disable all rules on a line, use the same comments without a rule name, for example // eslint-disable-line or // eslint-disable-next-line. To disable several rules, list them separated by commas, such as // eslint-disable-line no-alert, quotes, semi. These methods also work for plugin rules, where you combine the plugin name and rule name, for example example/rule-name.

    You can explain why the rule is disabled by adding a description after the configuration, separated from it by two or more consecutive - characters, for example // eslint-disable-next-line no-console -- reason here.

    Inline disabling should be used with caution and only for a clear, valid reason, not as the default way to resolve linting errors. If the disable is a temporary measure, create a follow-up task to address the underlying problem. Where possible, prefer configuration files over disable comments, since they give consistent, project-wide rule handling.

    Answered from Configure Rules — Use configuration comments, Configure Rules — Comment descriptions

  • How do I ignore files?

    You can ignore files in two ways: in your configuration file, or on the command line.

    • eslint.config.js with globalIgnores(): Pass glob patterns to the globalIgnores() helper, for example globalIgnores([".config/*"]).
    • --ignore-pattern on the command line: Pass a pattern such as npx eslint. --ignore-pattern '.config/*'.

    Your patterns are added after ESLint's default ignores, which are **/node_modules/ and .git/. By default ESLint lints **/*.js, **/*.cjs, and **/*.mjs, and you can exclude these with globalIgnores() if needed.

    Directory patterns work differently from .gitignore. A pattern like .config/ only matches the directory in the same folder as the configuration file. To ignore every directory with that name, use **/.config/.

    When you pass directories to the CLI, ignored files are skipped silently. If you pass a specific ignored file, ESLint warns that it was skipped. Use --no-ignore to turn off the ignore settings, including --ignore-pattern and the ignores property.

    You can also name the ignore config by adding a second argument to globalIgnores(), which helps with debugging.

    Answered from Ignore Files, Ignore Files — Ignore Files, Ignore Files — Ignore Directories, Ignore Files — Ignored File Warnings, Command Line Interface Reference — Ignore Files, Ignore Files — Name the Global Ignores Config

  • How do I extend a shared config?

    To extend a shared config, import the shareable config package inside your eslint.config.js file and add it to the extends array of a configuration object. The shareable config is an npm package that should be installed as a dependency in your project first. The extends key is an array, and each element can be a string naming a configuration in a plugin, a configuration object, or a configuration array. A configuration array can be inserted directly into extends, whether the shareable config exports an object or an array.

    You can limit the shared config to a subset of files by setting the files key on the configuration object that contains extends.

    You can override settings from the shared config by adding them directly into your eslint.config.js file after importing it, for example in a rules block in the same configuration object.

    If a package exports several configs, you can import the additional ones by their file path within the package and list them together in the extends array.

    Answered from Share Configurations — Use a Shareable Config, Configuration Files — Use a Shareable Configuration Package, Configuration Files — Extending Configurations, Combine Configs — Apply a Config Array, Combine Configs — Apply a Config Object, Share Configurations — Sharing Multiple Configs

Add this to your own docs

Paste your docs address to try it, free and without signing up. Then it is one line of code.

DocusaurusGitBookMintlifyWordPressReadMeMkDocsVitePressStarlightSphinxHugoJekyllNext.jsGhostWebflow