最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - How to force eslintprettier to not touch class member modifiers order? - Stack Overflow

programmeradmin4浏览0评论

Here is the problem:

When I run fixer then this

export class Test {
    public declare id: number;
}

transforms into this

export class Test {
    declare public id: number;
}

It is a problem for me because I'm new in the project and the old codebase have a lot of places with this order of modifiers public declare and when I run automatic eslint/prettier fixer it reorders them. But the older developer strictly wants me to keep old style, and his argument is:

access modifiers should come first

  1. How can I turn off this rule?
  2. Should I try to turn off this rule?

Is there a source where it is strictly declared in which order should I write modifiers of class members, so I will be able to argue with his argument :)

Maybe it is a bug of prettier like this one, and I need to report a new one


.prettierrc.json

{
    "trailingComma": "all",
    "tabWidth": 4,
    "printWidth": 120,
    "semi": true,
    "bracketSpacing": true,
    "endOfLine": "lf",
    "arrowParens": "avoid",
    "overrides": [
        {
            "files": "*.yml",
            "options": {
                "tabWidth": 2
            }
        }
    ]
}

.eslintrc.json

{
    "root": true,
    "env": {
        "browser": true,
        "es2020": true
    },
    "ignorePatterns": ["node_modules", "build", "dist", "*.config.js"],
    "parser": "@typescript-eslint/parser",
    "plugins": ["@typescript-eslint", "prettier", "unused-imports"],
    "parserOptions": {
        "project": "./tsconfig.json"
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:react-hooks/recommended",
        "prettier"
    ],
    "rules": {
        "no-console": [
            "warn",
            {
                "allow": ["warn", "error"]
            }
        ],
        "prettier/prettier": "warn",
        "unused-imports/no-unused-imports": "warn",
        "unused-imports/no-unused-vars": [
            "warn",
            {
                "vars": "all",
                "varsIgnorePattern": "^_",
                "args": "after-used",
                "argsIgnorePattern": "^_"
            }
        ],
        "react-hooks/exhaustive-deps": "off",
        "@typescript-eslint/no-unused-vars": "off",
        "@typescript-eslint/ban-ts-comment": "off",
        "@typescript-eslint/naming-convention": [
            "error",
            {
                "selector": "variable",
                "types": ["boolean"],
                "format": ["PascalCase"],
                "prefix": ["is", "has", "have", "should", "show", "can", "did", "will"]
            }
        ],
        "no-restricted-syntax": [
            "error",
            {
                "selector": "CallExpression[callee.name='Boolean']",
                "message": "Use '!!' instead of 'Boolean()' for type coercion."
            }
        ]
    }
}
Name Version
WebStorm 2024.3.2.1
Typescript 5.3.3
@typescript-eslint/eslint-plugin 6.7.4
eslint 8.26.0
prettier 3.5.3
发布评论

评论列表(0)

  1. 暂无评论