Usage and rules

Verze:

19. 06. 2025

Zodpovědná osoba:

Dominik Šlechta

Integrate ESLint into Your Build Process or Editor

  • Integrating with the Command Line:

    • You can run ESLint manually on your project by using the following command:

      npx eslint .  // Check all files in the current directory and subdirectories
      
  • Integrating with Build Tools

    • If you’re using build tools like Webpack or Gulp, you can integrate ESLint into your build process to automatically lint your code during the build process.
      • For Webpack: Use the eslint-webpack-plugin to lint your JavaScript files during the build.

      • For Gulp: Use gulp-eslint to run ESLint tasks.

  • Integrating with Your Editor

    • VSCode: Install the ESLint extension in VSCode to automatically lint your code as you write it.
    • PHPStorm:
      1. Install ESLint Plugin:

        • Go to Preferences (macOS) or Settings (Windows/Linux) in PhpStorm.

        • Navigate to Plugins and search for ESLint. Click Install and restart PhpStorm.

      2. Configure ESLint:

        • Go to Preferences/Settings > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint.

        • Enable Automatic ESLint configuration or manually point to your .eslintrc file, ensuring ESLint is properly configured.

Override or Add Custom Rules

  • You can easily customize ESLint's rules in your .eslintrc configuration file to better suit the specific needs or coding standards of your project.

  • Example of Customizing Rules:
    If you want to enforce the use of single quotes for strings and disallow console logs in production, you can add or modify rules in the .eslintrc file:

    {
      "extends": "google",
      "rules": {
        "quotes": ["error", "single"],  // Enforce single quotes for strings
        "no-console": ["error", { "allow": ["warn", "error"] }]  // Allow only console.warn and console.error
      }
    }
    

Summary

  • Integrate ESLint into your build process or editor to automatically check your code for style violations and errors.

  • Customize ESLint rules by editing the .eslintrc file to override or add rules that fit your project.