Closed dylanjha closed 6 years ago
Hey!
These are desired behaviors. In the "Example 1" we prefer whitespace formatting of prettier before standard's rules. This is whole point of prettier-standard. Not sure how I can help here :/
As for the second example, for the same reason you'd need to use eslint-disable-next-line
@sheerun thanks.
Is it not common (nor suggested) to both use prettier-standard
(for formatting) & run standard
(for linting)
(from the README):
While standard is a linter, prettier-standard is a formatter.
For example, I want to use the linter to catch things like unused variables, not handling errors, etc. What is the recommended way to achieve this?
You need to disable whitespace checking in your .eslintrc, something like so:
{
"rules": {
"indent": "off"
}
}
Gotcha, thanks for that. One thing I'm a little unclear about:
.eslintrc
meant to tell the standard
CLI to ignore the indent rule? Or is it telling prettier-standard
to ignore the indent rule? I would expect it to be the latter.Either way, as I'm trying this it doesn't seem to be working:
{"rules": {"indent": "off"}}
standard --fix
(fixes whitespace so standard is happy)prettier-standard
- whitespace gets fixed according to prettier
's rules, so now standard is no longer happyUsing: standard (10.0.3) prettier-standard (7.0.3)
I made a repo here demonstrating the above example: https://github.com/dylanjha/sample-prettier-standard, there is a .eslintrc
file in the root directory. If anyone pulls this down you can run:
yarn lint
(standard passes)yarn format-prettier
yarn lint
(standard fails)Thank you for taking the time, appreciate the help. Cheers š»
both eslint and prettier-standard will respect that .eslintrc (but prettier-standard ignores any non-fixable rules, and indentation is probably one of them).
I'm not sure that standard
respects .eslintrc, you probably need to use https://github.com/standard/eslint-config-standard instead
Also prettier-standard should be run before eslint/standard
Hope you manage to fix your setup
Gotcha, thanks sheerun. In my example prettier-standard is fixing indentation rules, but it is ignoring the .eslintrc config. Never got to the bottom of that, but that ended up not being a blocker for me. In case anyone finds this thread, I managed fixing my setup by doing this:
Pre commit hook:
prettier-standard
(this will edit whitespace stuff + all the other prettier rules)standard --fix
(this will edit whitespace stuff again to make it compliant with standard, it will fail if there are any non-fixable standard rules being broken)On CI:
standard
to lint for StandardJS compliance.
Using:
My goal here, which I think is a common use case is to use prettier-standard in a pre-commit hook to format the code that gets committed. I also want to have the code that gets committed be compliant with StandardJS. Ultimately, the CI server will run the
standard
CLI command on the relevant directories to confirm that the code passes the StandardJS linting rules.I have a couple examples below where the code passes the
standard
command before runningprettier-standard
but does not pass thestandard
command afterprettier-standard
does the formatting.I have supplied a small gist here with the starting code for both Example 1 and Example 2: https://gist.github.com/dylanjha/1d07f355636e15293df46c9db6781c5d
Thank you to anyone who can chime in š . Perhaps I'm going about this the wrong way or missing something obvious here.
Example 1
I have a file that looks like this:
Right now, this file is compliant with StandardJS, running the
standard
cli passes.Now I run
prettier-standard
, here's what I get, which looks nice šProblem is, this file is no longer StandardJS complaint, running the
standard
CLI fails:Example 2
Starting with this code
StandardJS has a rule to pass in error objects to
reject
(not strings). This rules is being explicitly disabled with the in-line comment, so this code passes the StandardJSstandard
CLI command.When prettier runs, it reformats the code to look like this:
Now, because the eslint-disable comment was moved to it's own line, the code is no-longer compliant with StandardJS and no longer passes the
standard
command.