prettier / eslint-plugin-prettier

ESLint plugin for Prettier formatting
https://npm.im/eslint-plugin-prettier
MIT License
3.33k stars 182 forks source link

Prettier enforces adding unnecessary parentheses #640

Closed SiarheiRashchynski closed 9 months ago

SiarheiRashchynski commented 9 months ago

What version of eslint are you using?

8.56.0

What version of prettier are you using?

3.2.4

What version of eslint-plugin-prettier are you using?

5.1.3

Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files)

// eslint

{
    "env": {
        "es2021": true,
        "node": true
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project": ["./tsconfig.json"]
    },
    "overrides": [
        { 
            "files": ["**/__tests__/**/*.ts"],
            "rules": {
                "@typescript-eslint/explicit-member-accessibility": "off",
                "@typescript-eslint/no-explicit-any": "off",
                "@typescript-eslint/quotes": ["warn", "single"]
            }
        },
        { 
            "files": ["**/*.decorator.ts"],
            "rules": {
                "@typescript-eslint/no-explicit-any": "off"
            }
        }
    ],
    "plugins": ["@typescript-eslint", "import", "prettier"],
    "rules": {
        "@typescript-eslint/lines-between-class-members": ["error", "always"],
        "@typescript-eslint/indent": ["error", 4],
        "@typescript-eslint/quotes": ["error", "single"],
        "@typescript-eslint/semi": ["error", "always"],
        "@typescript-eslint/no-unused-vars": "warn",
        "@typescript-eslint/member-ordering": "error",
        "@typescript-eslint/explicit-member-accessibility": "error",

        "import/order": [
            "warn",
            {
                "groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
                "newlines-between": "always",
                "alphabetize": {
                    "order": "asc",
                    "caseInsensitive": true
                }
            }
        ],

        "max-len": ["warn", { "code": 120 }],
        "comma-dangle": ["warn", "only-multiline"],
        "eol-last": ["error", "always"],
        "linebreak-style": ["error", "unix"],
        "prettier/prettier": "warn"
    },
    "extends": ["plugin:@typescript-eslint/recommended", "prettier"]
}

// prettier

{
    "tabWidth": 4,
    "printWidth": 120,
    "singleQuote": true,
    "endOfLine": "lf"
}

// tsconfig

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "outDir": "dist",
        "importHelpers": true,
        "strict": true,
        "esModuleInterop": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    },
    "types": ["node", "jest"],
    "include": ["src/**/*.ts", "jest.config.js"],
    "exclude": ["node_modules"],
    "compiledFiles": ["dist/**/*.js"]
}

What source code are you linting?

describe('Test', () => {
    let commandHandler: RemoveBlackholeCommandHandler;
    let storage: jest.Mocked<Storage>;
    let cryptoProvider: jest.Mocked<CryptoProvider>;

    beforeEach(() => {
        privateDirectoryAccessor = {
            delete: jest.fn(),
        } as any,
        cryptoProvider = {
            check: jest.fn(),
        } as any;
        storage = {
            save: jest.fn(),
            blackholes: {
                delete: jest.fn(),
                get: jest.fn().mockResolvedValue(blackhole),
                save: jest.fn(),
            },
        } as any;

        commandHandler = new RemoveBlackholeCommandHandler(storage, cryptoProvider, privateDirectoryAccessor);
    });
});

What did you expect to happen?

I expected Prettier to recognize that the parentheses in the beforeEach block are not necessary around privateDirectoryAccessor and cryptoProvider assignments. The code should be formatted without parenthese

What actually happened?

Pettier suggests to me to add unnecessary parentheses around those functions. It doesn't suggest adding parentheses around storage assignment even though it's the same

beforeEach(() => {
        (privateDirectoryAccessor = {
            delete: jest.fn(),
        } as any),
        (cryptoProvider = {
            check: jest.fn(),
        } as any);
        storage = {
            save: jest.fn(),
            blackholes: {
                delete: jest.fn(),
                get: jest.fn().mockResolvedValue(blackhole),
                save: jest.fn(),
            },
        } as any;

        commandHandler = new RemoveBlackholeCommandHandler(storage, cryptoProvider, privateDirectoryAccessor);
    });

image

SiarheiRashchynski commented 9 months ago

Sorry, there was my mistake, I overlooked a comma