Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not respecting es6 prefer-* rules like prefer-arrow-callback. #149

Closed
cancerberoSgx opened this issue Dec 9, 2017 · 5 comments
Closed

Comments

@cancerberoSgx
Copy link

cancerberoSgx commented Dec 9, 2017

I'm reporting this issue in the form of a very simple node.js project that demonstrate it. basically prettier-eslint is not respecting "prefer-arrow-callback": "error" and more - it seems it it removing or preventing eslint to do it. In the project I'm calling prettier and eslint --fix separately and that works OK but with prettier-eslint it doesn't . It also happens with other es6 "prefer" fixable rules like functions to methods, etc

https://github.com/cancerberoSgx/prettier-eslint-gallery/tree/master/misc/prettier-eslint-issue

Basically all popular styleguides are broken in prettier-eslint if in my case you must force arrow functions for callbacks, methods, etc

I'm using a very simple api call:

var fomatted = format({
    text: shell.cat(input).toString(),
    filePath: path.resolve(config),
    logLevel: 'debug'
})

prettier-eslint logs don't show any error or mistake.

@cancerberoSgx cancerberoSgx changed the title not transforming functions into arrow functions - not respecting es6 prefer* rules - popular styleguides broken not respecting es6 prefer-* rules like prefer-arrow-callback. Dec 9, 2017
@cancerberoSgx
Copy link
Author

cancerberoSgx commented Dec 12, 2017

BTW, this is my poor man's prettier-eslint implementation - I'm using your's require('../../node_modules/prettier-eslint/dist/utils.js').getOptionsForFormatting for inferring eslint prettier rules from eslint's config which does excellent job.

// implements prettierEslint's API 
function homeMadePrettierEslint(options) {
    //prettier first
    var prettierConfig = getPrettierConfigFromEslint(options.filePath)
    var prettier = require('prettier')
    if (options.logLevel) {
        console.log('Prettier options: ', JSON.stringify(config))
    }
    var code = prettier.format(options.text, prettierConfig)

    //eslint last:
    var eslintConfig = getEslintConfigFromPath(options.filePath)
    var Linter = require('eslint').Linter
    var linter = new Linter()
    var messages = linter.verifyAndFix(code, eslintConfig)
    if (options.logLevel) {
        console.log('Eslint config: ', JSON.stringify(eslintConfig))
    }   
    if (options.logLevel) {
        console.log('Eslint config: \n', JSON.stringify(eslintConfig))
        console.log('\nEslint verifyAndFix output; \n', JSON.stringify(messages))
    }
    return messages.output
}


// home made implementation:
function getEslintConfigFromPath(eslintConfigPath, eslintOptions = {}) {
    const { CLIEngine } = require('../../node_modules/eslint')
    var eslintCli = new CLIEngine(eslintOptions)
    const config = eslintCli.getConfigForFile(eslintConfigPath)
    return config
}

function getPrettierConfigFromEslint(eslintConfigPath) {
    var config = getEslintConfigFromPath(eslintConfigPath)
    var getOptionsForFormatting = require('../../node_modules/prettier-eslint/dist/utils.js').getOptionsForFormatting
    var prettierConfig = getOptionsForFormatting(config)
    return prettierConfig.prettier
}

@zimme
Copy link
Member

zimme commented Dec 12, 2017

I'm just wondering if this is related to the following issue.
prettier/eslint-plugin-prettier#65

@cancerberoSgx
Copy link
Author

cancerberoSgx commented Dec 12, 2017

https://prettier.io/docs/en/eslint.html - says:

.....disable the conflicting rules (while keeping around other rules that Prettier doesn't care about). The easiest way to do this is to use eslint-config-prettier. It's a one liner that can be added on-top of any existing ESLint configuration

It is not a prettier-eslint dependency but if I do npm install I see the module installed in node_modules so I guess is an indirect dependency. Probably is this... Doing npm ls :

....
├─┬ eslint-config-kentcdodds@13.0.1
.......
│ ├─┬ eslint-config-prettier@2.9.0
......

don't know what this "eslint-config-kentcdodds": "^13.0.1", does I will try to remove it from my local prettier-eslint and see if this issue is still reproducible.
Unfortunately I don't have much time to investigate - and I have more or less resolved my problem.

@zimme
Copy link
Member

zimme commented Dec 12, 2017

Well, I don't think that what they are talking about is a problem with the plugin package but about that prettier and eslint have conflicting fixes for prefer-arrow-callbacks and that's the problem they want to solve by disabling the eslint rule in the plugin/config package.

I'll look into this a bit later.

@zimme
Copy link
Member

zimme commented Jan 17, 2018

Try with latest prettier-eslint and tell me if this issue isn't resolved and I'll re-open the issue.

P.S. I do believe this might be related to prettier/eslint-plugin-prettier#65

@zimme zimme closed this as completed Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants