Skip to content

apify/apify-eslint-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apify-eslint-config

This repository contains a shared eslint config used across Apify. It offers several configs:

  • JavaScript config @apify/eslint-config/js
  • TypeScript config that also includes JavaScript config @apify/eslint-config/ts
  • Jest config that only applies to test files and folders @apify/eslint-config/jest
  • Vitest config that only applies to test files and folders @apify/eslint-config/vitest
  • Opt-in stylistic rules @apify/eslint-config/style (see below)

How to add to your project

First install the packages as development dependencies:

npm install --save-dev @apify/eslint-config eslint

Optionally, you can install:

  • typescript-eslint if you intend to use TypeScript,
  • eslint-plugin-jest if you intend to use Jest for testing,
  • @vitest/eslint-plugin if you intend to use Vitest for testing.

Add eslint.config.js file, here's an example configuration for a TypeScript project using ESM and Jest for tests:

import apifyTypescriptConfig from '@apify/eslint-config/ts';
// Optional
import apifyJestConfig from '@apify/eslint-config/jest';

export default [
    ...apifyTypescriptConfig,
    ...apifyJestConfig,
    {
        languageOptions: {
            sourceType: 'module',
            parserOptions: {
                projectService: true,
                tsconfigRootDir: import.meta.dirname,
            },
        },
    },
];

An example configuration for a JavaScript project using CommonJS without Jest:

const apifyJsConfig = require('@apify/eslint-config/js');

module.exports = [
    ...apifyJsConfig,
];

An example configuration for a JavaScript project using ESM and Vitest for tests:

import apifyJsConfig from '@apify/eslint-config/js';
import apifyVitestConfig from '@apify/eslint-config/vitest';

export default [
    ...apifyJsConfig,
    ...apifyVitestConfig,
];

Stylistic rules (opt-in)

The base config does not enforce stylistic / formatting rules — Prettier (or any other formatter) is the recommended way to handle those. If you have a strong reason not to use a formatter and want to keep the airbnb-style stylistic ruleset, install @stylistic/eslint-plugin and add the opt-in @apify/eslint-config/style config:

npm install --save-dev @stylistic/eslint-plugin
import apifyTypescriptConfig from '@apify/eslint-config/ts';
import apifyStyleConfig from '@apify/eslint-config/style';

export default [
    ...apifyTypescriptConfig,
    ...apifyStyleConfig,
];

This adds 58 stylistic rules (indent, quotes, semi, comma-dangle, space-before-blocks, keyword-spacing, max-len, etc.) with the same options eslint-config-airbnb-base used to enforce, rewritten as @stylistic/* rules so they work with eslint v9 + flat config. If you're using Prettier, do not include this config — the rules will conflict with your formatter.

About

Apify ESLint preset to be shared between projects

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors