如何为剧作家配置 eslint?

问题描述 投票:0回答:1

随着时间的推移,配置文件格式等 eslint 发生了变化,我发现谷歌搜索和其他问题/答案令人困惑,对我不起作用。他们强迫我使用 cjs 文件,然后我遇到了格式问题,而且一团糟。

有一套当前时间的程序在今天效果很好吗?

eslint playwright
1个回答
0
投票
  1. (至少)位于节点 18 上,否则您将收到有关“rules”键的令人困惑的错误消息

  2. 初始化eslint

   npm init @eslint/config@latest`
  1. 安装以下内容
   npm install eslint
   npm install eslint-plugin-playwright
   npm install @typescript-eslint/eslint-plugin
  1. 使用您认为适合您的项目的规则,将步骤 2 中创建的
    eslint.config.js
    修改为如下所示:
import js from '@eslint/js';
import playwright from "eslint-plugin-playwright";
import typescriptEslintPlugin from '@typescript-eslint/eslint-plugin';
import typescriptEslintParser from '@typescript-eslint/parser';

export default [
  js.configs.recommended,
  {
    plugins: {
      '@typescript-eslint': typescriptEslintPlugin
    },
    files: ['e2e/**/*.[jt]s'],
    rules: {
      "indent": ['error', 2],
      "max-len": ['error', 100],
      "quotes": ['error', 'single'],
      "eqeqeq": "error",
      "semi": "error",
      "no-var": "error",
      "no-new": "error",
      "vars-on-top": "error",
      "default-param-last": "error",
      "no-tabs": "error",
      "no-trailing-spaces": "error",
      "no-nested-ternary": "error",
      "no-multiple-empty-lines": "error",
      "no-extra-parens": "error",
      "default-case": "error",
      "no-unused-vars": "error",
      "prefer-const": "error",
      "no-const-assign": "error",
      "no-constant-binary-expression": "error",
      "no-constant-condition": "error",
      "no-dupe-args": "error",
      "no-dupe-else-if": "error",
      "no-dupe-keys": "error",
      "no-duplicate-case": "error",
      "no-duplicate-imports": "error",
      "no-empty-pattern": "error",
      "no-irregular-whitespace": "error",
      "no-undef": "error",
      "no-unexpected-multiline": "error",
      "no-unreachable": "error",
      "no-unreachable-loop": "error",
      "camelcase": "error",
      "consistent-return": "error",
      "max-lines": ["error", 120],
      "no-else-return": "error",
      "no-eq-null": "error",
      "no-eval": "error",
      "no-loop-func": "error",
      "no-native-reassign": "error",
      "no-param-reassign": "error",
      "no-self-compare": "error",
      "prefer-template": "error",
      "comma-spacing": "error",
      "no-multi-spaces": "error",
      "space-in-parens": ['error', 'never'],
      "array-bracket-spacing": ['error', 'never'],
      "accessor-pairs": "error",
      "grouped-accessor-pairs": "error",
      "block-scoped-var": "error",
      "no-implicit-coercion": "error",
      "no-invalid-this": "error",
      "no-magic-numbers": ["error", { "ignoreDefaultValues": true }],
      "no-useless-return": "error",
      "prefer-regex-literals": "error",
      "require-await": "error",
    },
    languageOptions: {
      ecmaVersion: 2022,
      parser: typescriptEslintParser,
      parserOptions: {
        sourceType: 'module'
      },
    },
  },
  {
    plugins: { playwright },
    files: ['**/*.spec.[jt]s'],
    ...playwright.configs['flat/recommended'],
    rules: {
      "playwright/no-skipped-test": "error",
      "playwright/no-commented-out-tests": "error",
      "playwright/prefer-comparison-matcher": "error",
      "playwright/prefer-equality-matcher": "error",
      "playwright/prefer-strict-equal": "error",
      "playwright/prefer-to-be": "error",
      "playwright/prefer-to-contain": "error",
      "playwright/prefer-to-have-count": "error",
      "playwright/prefer-to-have-length": "error",
      "playwright/require-top-level-describe": "error",
      "playwright/valid-expect": "error",
      "playwright/prefer-hooks-in-order": "error",
      "playwright/prefer-hooks-on-top": "error",
    }
  }
];
© www.soinside.com 2019 - 2024. All rights reserved.