TristonJ / eslint-plugin-prefer-arrow

ESLint plugin to prefer arrow functions
MIT License
54 stars 10 forks source link

Issue with fix #11

Closed amritk closed 4 years ago

amritk commented 5 years ago

There seems to be a strange bug here, this is on a typescript file. It fixes this:

Vue.use(Vuetify, {
    theme: {
        primary: '#008940',
        accent: '#0279D7',
        secondary: '#9F9F9F',
        info: '#0279D7',
        warning: '#B71C1C',
        error: '#B71C1C',
        success: '#4CAf50'
    },
    options: {
        minifyTheme (css: string) {
            return process.env.NODE_ENV === 'production'
                ? css.replace(/[\s|\r\n|\r|\n]/g, '')
                : css
        }
    }
})

2019-04-18:16:45:44 To this:

Vue.use(Vuetify, {
    theme: {
        primary: '#008940',
        accent: '#0279D7',
        secondary: '#9F9F9F',
        info: '#0279D7',
        warning: '#B71C1C',
        error: '#B71C1C',
        success: '#4CAf50'
    },
    options: {
        minifyTheme : 
    }
})

2019-04-18:16:47:05

felixfbecker commented 4 years ago

I have the same problem. Autofix in TypeScript files seems to remove the function.

TristonJ commented 4 years ago

Thank you for the report. I have never tried the plugin on a TypeScript file. I'll write some tests using the @typescript-eslint/parser and see if I can replicate this issue.

petemcwilliams commented 4 years ago

Also came across the same issue, any progress ?

export function dummyFunction(testString: string):string {
    return testString;
}

replaced with

export ;

index.js

module.exports = {
    env: {
        browser: true,
        es6: true,
        node: true,
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:sonarjs/recommended',
        'plugin:jsdoc/recommended',
        'plugin:prettier/recommended',
        'prettier/@typescript-eslint',
    ],
    parser: '@typescript-eslint/parser',
    parserOptions: {
        project: 'tsconfig.json',
        sourceType: 'module',
    },
    plugins: ['prefer-arrow', 'import', '@typescript-eslint', 'sonarjs', 'jsdoc'],
    rules: {
        '@typescript-eslint/array-type': 'error',
        '@typescript-eslint/await-thenable': 'error',
        '@typescript-eslint/ban-ts-ignore': 'warn',
        '@typescript-eslint/camelcase': [
            'error',
            {
                properties: 'never',
                ignoreDestructuring: true,
            },
        ],
        '@typescript-eslint/explicit-function-return-type': [
            'error',
            {
                allowExpressions: true,
                allowTypedFunctionExpressions: true,
                allowHigherOrderFunctions: true,
            },
        ],
        '@typescript-eslint/explicit-member-accessibility': [
            'error',
            {
                accessibility: 'no-public',
            },
        ],
        '@typescript-eslint/prefer-function-type': 'error',
        '@typescript-eslint/semi': ['off', null],
        '@typescript-eslint/space-within-parens': ['off', 'never'],
        '@typescript-eslint/typedef': [
            'error',
            {
                arrayDestructuring: false,
                arrowParameter: false,
                memberVariableDeclaration: false,
                objectDestructuring: false,
                parameter: false,
                propertyDeclaration: true,
                variableDeclaration: false,
            },
        ],
        'arrow-body-style': 'error',
        'arrow-parens': ['off', 'as-needed'],
        curly: 'error',
        eqeqeq: ['error', 'smart'],
        'handle-callback-err': 'error',
        'id-blacklist': ['error', 'any', 'Number', 'number', 'String', 'string', 'Boolean', 'boolean', 'Undefined', 'undefined'],
        'id-match': 'error',
        'import/no-deprecated': 'warn',
        'import/no-unassigned-import': 'error',
        'import/order': 'error',
        'jsdoc/require-jsdoc': 'warn',
        'jsdoc/require-param-type': 'off',
        'jsdoc/require-returns': 'off',
        'no-caller': 'error',
        'no-console': 'error',
        'no-duplicate-imports': 'error',
        'no-eval': 'error',
        'no-invalid-this': 'error',
        'no-new-wrappers': 'error',
        'no-proto': 'error',
        'no-script-url': 'error',
        'no-self-compare': 'error',
        'no-unneeded-ternary': 'error',
        'no-return-await': 'error',
        'no-sequences': 'error',
        'no-shadow': [
            'warn',
            {
                hoist: 'all',
            },
        ],
        'no-template-curly-in-string': 'error',
        'no-throw-literal': 'error',
        'no-undef-init': 'error',
        'no-undefined': 'error',
        'no-underscore-dangle': ['error', { allowAfterThis: true }],
        'no-unused-expressions': [
            'error',
            {
                allowShortCircuit: true,
            },
        ],
        'object-shorthand': 'error',
        'one-var': ['off', 'never'],
        'prefer-arrow-callback': 'off',
        'prefer-arrow/prefer-arrow-functions': [
            'warn',
            {
                disallowPrototype: false,
                singleReturnOnly: true,
                classPropertiesAllowed: true,
            },
        ],
        radix: 'error',
    },
};
TristonJ commented 4 years ago

Sorry this took me a while, but this should be fixed in https://github.com/TristonJ/eslint-plugin-prefer-arrow/commit/00ac120a12bdf95d34ba09d18d96c1f3c4d8dedf and available in version 1.1.7 of the npm package.

If there are any further issues with typescript & this plugin, feel free to open another issue.