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
Autocorrect? #330
Comments
I think so.
I like this idea.
In
Taking a quick look through the rules. I reckon the majority of the |
My reservation about the 0,1,2,3 idea is that then the numbers make less sense (when they probably don't make a lot of sense to some users to begin with). The "3" would mean they no longer correspond meaningfully to an exit code. If we wanted that flag to do all of this, I don't know, maybe we would be better off using keywords: "ignore", "warn", "autocorrect"? Another thought I had: I imagine that for many people's builds autocorrection would be part of a new standalone process. Most of the time with PostCSS they are transforming code and outputting new files; but autocorrection would call for overwriting the original files. Also, most people probably include I'm curious what @MoOx has to say, and will try to solicit some input on the Twitter. |
Good point.
It certainly is clearer.
Yes, I think so. It might be that autocorrecting is only enabled if stylelint is being used as a standalone tool, otherwise only linting is available.
Defo. It feels like it could be a contentious issue that would benefit from having a few more eyes cast over it :) |
I have to admit that autocorrect would be a nice feature. But making this "automatic" seems a bit crazy at first. Like you said, code will be weird (and string will be a pain for configuration imo). JSCS have a similar feature and I think it's more reserved to stylistic rules (indent, whitespace etc) but maybe I am wrong. From my memory there is a jshint things to autocorrect some rules too. I am not really for this feature, but at the same time, I am not against it. This will require some reflexions for a good UX in order to make this clear (bad ux might be "magic" & silent automatic changes without noticing the user). Maybe this would be a feature with a interactive mode? Or at least a feature with some (OS) notifications? |
I think I'm not understanding all your points, @MoOx ... I think there's no suggestion to make it "automatic" or "all the time": you'd opt-in just like you would to any of the linting. One question is: What is the best way for users to opt-in via the config? The user would definitely have to be aware of what's going on, or it wouldn't work. I don't think we would end up performing magic that would surprise them. They'd need a process set up to overwrite their existing files rather than run a PostCSS process that outputs new files. Also, I agree that the changes shouldn't be silent: we could issue messages (not warnings) that say "Changing x to y". I think this is the kind of thing that people would like to have in their text editor: when you hit save, it cleans up your little spacing mistakes and inconsistent hex capitalization, etc. |
What will happen if someone put a 3 in it's config that is "just" supposed to lint. Will it fix on runtime only? Will it overwrite the file? |
We could make the config able to lint and autocorrect at the same time. Currently, nothing will get overwritten, though, unless you set up a PostCSS process that does the overwriting. I guess once we have our standalone tool we should make it overwrite the file if you have any autocorrects on. So you're suggesting a single option that turns on all the autocorrect possibilities at once? We could do that as well as having the ability to turn on each individually. Yes, that would be useful to clean up old files; but I think people would also use it for stuff they are working on, so that instead of getting a warning when they miss a space it is just taken care of for them. |
I am just thinking about UX. Why someone would want to get something fixed during a build? I see two use cases for a linter:
Sure we can mix both, I just found this weird. The main purpose of a linter is to teach, not to fix, but I totally get the feature (and I would enjoy it for old crappy code I have to work on 2 years later!). I don't really think it's a good idea to allow something to fix mistakes automatically so easily, but maybe it's just my point of view. So if everyone think it's a good idea, do it :) Btw, it will be easy with the upcoming cli tool to fix a folder directly. Maybe we should take a look to jscs that have a similar issue (but this one is mainly a style checker so it just fix code style) http://jscs.info/overview.html#-fix-x. Doc is not really clear on the way this is behaving on files... |
I also would like to have my mistake pointed out and fix it myself. But I have a lot of teammates who would prefer the autocorrect, and I get that, too. My reservation about the JSCS way is that users can't then pick and choose which rules get autocorrected, which don't. They just autocorrect everything. I guess maybe no users will want to pick and choose? If that's the case, we should just use a single universal setting like you suggested (which also could be set via CLI flag). |
The point of a linter is to ensure code quality. Since most of the time code is versionned, I don't see why keeping a non valid code (per linter configuration) might make sense. For example if I decide that a codebase won't have any vendor-prefix, I don't want a team mate to have them "fixed" (removed, then probably added back by autoprefixer, maybe with different values...). This seems weird to allow such things. But maybe I am missing something here. JSCS by have no default rules on, so you need to define your code style. I think it make sense to use --fix to fix all the possible things in the scenario where you want to change code style. |
@jeddy3: Any thoughts on whether we should just have a blanket "fix" flag, or allow users to choose precisely which rules get autocorrected? |
I'd first like to revisit the rationale behind this feature as, after re-reading the discussion above, I'm now unsure whether we should implement it. On a couple of occasions we've discussed the scope of this project and we've tended to make decisions that keep the project as narrowly-focused as possible. I think we've been right to be cautious of feature-creep as it's helped keep the project maintainable, manageable and approachable to new contributors. We've also aimed for consistency at every opportunity, including the names, options, messages, and behaviour of each rule. I think this has helped create a good user experience. We've added a few features recently, such as plugins and options validation. I think these features feel easily justifiable in their support of our goal to create a JavaScript-based pluggable linter for future and current CSS . Plugins were the key to allowing a user to extend the tool to support their processor plugin choices and any idiosyncratic aspects of their own coding styles. While the options validator instilled confidence in the user that the linter was configured correctly. By contrast, I think this feature moves us away from being a linter and towards being a linter and a fixer. A fixer that will have inconsistent behaviour i.e. not all rules can be autofixed. I can envisage a user wanting to autofix everything, but being disappointed that it only works for some of the rules. I think I'd rather see stylelint as a consistent, predictable and reliant linter, than a consistent linter with an inconsistent fixer built into it. I think if the addition was an easy one to implement it might be easier to justify, but as this discussion has already shown and along with the discussions they seem to be having it at eslint it seems like adding autofixing is fraught with obstacles. The points above apply to both use cases i.e. a user adjusting old code to a new standard and a user wanting to autofix code they're currently working on. I have a little more to say about the former use case... When we started working on stylelint there weren't any JavaScript-based pluggable linters, with useful reporting, for future and current CSS out there. There are plenty of fixers though... If you inherit an old code base and if you choose (via this comment) to clean up the existing styles, then there's plenty of tools out there to help you do this:
Not all these tools have the same depth of support for things like commas at the beginning of lines, but I think these are compromises you'd need to make if you choose to refactor an old code base. Perhaps we should hold-off until we see how eslint clears some of the hurdles and how the other fixer tools evolve. I think then we'll be in a better position to decide if adding this feature to stylelint (along with the necessary support and inconsistency it will require) is worth it. What do you both think? |
Yeah, we can wait and see. I'm not attached to the autocorrect, idea, fine
All that said, it would be a lot of work. Feel free to close this issue if On Wed, Aug 5, 2015 at 9:39 AM, Richard Hallows notifications@github.com
|
If you "fix" some code during development, you are another preprocessor :) We can leave this open until others people express their point of view. |
Sorry I did not read everything above but... This would be absolutely fantastic. Being able to make the code work and not have to bother much about formatting. And then clean it up with a command in Atom, or whatever, before making the commit. |
I hadn't really thought through the idea of using commands in editors before, but now I see how this could be very useful.
If it's a command in the editor, will the editor's undo feature handle the versioning? @davidtheclark makes three strong arguments for this feature too...
I think I'm becoming one of those people :)
Yeap, I understand that now.
I agree with this. All that being said, I do agree that this will be a lot of work. Also, it looks like there are two postcss autofixers in the works https://github.com/morishitter/cssfmt and https://github.com/ben-eb/perfectionist/. It is a shame, like you said, that they'll need to duplicate chucks of the logic we've already written. @AntonTrollback There's an Atom plugin for cssfmt that you can use alongside the stylelint one (if your styles match cssfmt's opinionated one's that is). |
Hi, I'm morishitter, author of CSSfmt. Sorry I did not read everything above too. I think, lint tools should not support auto-correcting because it may change destructively. For example, if and I wonder if the options for formatting CSS source code is necessary to us? One of this reason is, I found stylelint can do it. and second is, I thought that no one want to write So, I create CSSfmt without options for formatting like Gofmt. @jeddy3 What can I do for you concretely? I think stylelint replace with csslint in the future, and I like stylelint. I'd like to work with you :) |
Oops, nothing now that I realise csscs was discontinued in favour of cssfmt :) Perhaps, we should add a "Formatters and Beautifiers" bit to the "Complementary tools" section of the readme? And include in CSSfmt there as it'd help the likes of @AntonTrollback find a formatter. I'll create a PR to see what the other guys think. |
Thank you @jeddy3 :) will check it out |
I don't have any problem leaving this task to CSSfmt (which is great, @morishitter — thanks!). I do think it would make a good addition to our Complementary Tools section. Should we close this issue, then, if everybody's ok with leaving autocorrection to CSSfmt? |
SGTM. |
Skipped to bottom of thread. Solution was to use CSSfmt. CSSfmt is cool, but has nothing to do with stylelint.. https://github.com/morishitter/cssfmt#basic sets it own rules - not rules based off stylelint configurations. I've opened an issue there. In the meantime this should be reopened. |
@corysimmons: This thread discusses exactly what you asked for. People did not seem to be interested in having stylelint autocorrect. If you want to voice your reasons for including autocorrect, please do. |
My reasons are the same as anyone's. Who wants to go through hundreds of stylesheets manually conforming them to a particular stylelint config? (I'm literally doing this exact thing right now and it's as horrible and human-error-prone as it sounds) What happens if you update that stylelint config? Now you have to manually go through hundreds of files again. I understand that you'd have to do this anyway since autocorrect couldn't get everything perfect, but if it cuts the amount of stylelint errors in a file down from 300 errors to 3 errors, that's a huge amount of time saved. Just make it a flag --autocorrect :warning: **This will overwrite your file(s). Make sure you have them backed up somewhere safe (like GitHub) before running this.** If some idiot:
Then they deserve to have their project wiped out. Newbs gonna newb but it's the only way they learn. Why punish everyone who could actually use this feature because 1 or 2 newbs format their css in a way they don't like and pee their pants about it? Anyway, I actually don't care if this is built into stylelint or not (it'd be nice to have an official version and I wouldn't have to install multiple programs), but I definitely think it's at least worth keeping this issue open in case some super hero comes along and wants to make a CSSfmt that accepts stylelint configs. CSSfmt in it's current state honestly has nothing to do with stylelint whatsoever and isn't an appropriate solution to this Issue. |
Just to follow up on @jeddy3 comment above regarding ESLint, Eslint have now implemented autofixing via eslint/eslint@a5d17b4 and CLI docs: eslint.org/docs/user-guide/command-line-interface.html#fix
Example rule that supports fixable rules: http://eslint.org/docs/rules/comma-spacing.html |
@ntwb Nice, thank you. The ESLint dudes are pretty smart. =) |
I'd love to see this myself although i'm not sure if i'd use it (Since we have Stylelint from the start things are already in the style i want) but i do think @morishitter raises a pretty good point. How do we handle situations like stripping |
You would run Again, if someone is stupid enough to:
Then they deserve to have bad things happen to them. It doesn't mean the rest of us shouldn't be able to write a config that removes So far as everyone being paranoid about the destructive nature of this, why not just force a non-input output file and confirm overwrite if the user tries to run For instance: $ stylelint -i input.css --config standard --fix
Error: You must provide a unique output file when using --fix.
$ stylelint -i input.css -o input.css --config standard --fix
Error: You must provide a unique output file when using --fix.
$ stylelint -i input.css -o output-that-exists.css --config standard --fix
Overwrite the contents of output-that-exists.css? y/N
$ stylelint -i input.css -o output-that-doesnt-exist.css --config standard --fix
Success! Created output-that-doesnt-exist.css with clean CSS! |
I agree it should remove the |
👍 |
I’d love to see an autocorrect option for things that can be fixed safely. I already use CSScomb to auto-fix /sort/format many things, but having the option to let stylelint do it instead (or in addition, since it doesn’t sort declarations) would be excellent. Overwriting the source file(s) with the fixed CSS is not a problem IMO. I’ve been doing it daily for 2-3 years with CSScomb, and with JSCS or eslint for JS. The only minor issue is that the overwrite will add a step to the undo buffer in some editors. |
I think that everybody likes the idea of autocorrect, but the real concern about adding autocorrect to stylelint is that it would introduce a ton of additional complexity. I have re-opened this issue to see if anybody wants to propose specific mechanisms (i.e. code) for implementing autocorrect within stylelint. Only with specific proposals can we assess whether this feature is worth the trouble it will cause. Also, introducing autocorrect would probably significantly increase the bug potential and maintenance burden of the project. So I will be unlikely to try to build in autocorrect unless we get more consistent contributors. |
I re-think about supporting styling configuration in CSSfmt ( masaakim/stylefmt#61 ) and may rename it to stylefmt. |
@morishitter 👍 It looks like the issue was opened to see how autocorrect could be simplified before implementing in stylelint itself but a separate tool would be great to cover it and is probably more desired to keep complexity down here. |
@morishitter: If you want to experiment with that path, sounds cool. I think there could be major advantages to having a separate tool that understands that same config. But I also think there may be disadvantages, if a lot of logic has to be duplicated between the tools, bugs fixed in both places, etc. (I wonder if the exposed I think the only way we could know for certain which way to go would be to start the experiment. Here's what I think might have to happen next:
|
@davidtheclark Thanks for your advise.
Exactly. I also take it into account.
Yep, I just want to know the list. From now on, I plan to read all stylelint rules and extract ones that related to code formatting, and refactor CSSfmt code to inject the other formatting rules. |
We definitely should have autocorrect, because right now Stylelint could be most powerful code style fixer tool. |
@ai Now, I'm updating CSSfmt to read stylelint configuration file for formatting code. I have finished almost, but I have to add some test code. It's coming soon :) |
Wow? can you write a tweet when you will finish it and ping me? Great idea. |
👍 |
For those interested in this issue there are some very exciting things happening in masaakim/stylefmt#79 :) |
Hi, I just released stylefmt (renamed from CSSfmt) v3.0.0, support to understand stylelint rules for formatting. https://github.com/morishitter/stylefmt/releases/tag/v3.0.0 Please try to use it :) |
@morishitter That's fantastic! I'm wondering if you could add to the docs a list of which stylelint rules stylefmt will handle? That was my first question, and I didn't find an answer. Want me to file an issue over there? |
@davidtheclark Thanks! These are the list of it https://github.com/morishitter/stylefmt/tree/master/test/stylelint . I will add then to the docs :) |
@morishitter that's wicked! |
I thought I'd throw out this idea:
If a person wanted to build a library that looked for the same code style issues but instead of warning about them, corrected them automatically — that person would have to rewrite the same logic that we have to find the issues, then just take a different action once they're found. Right?
Because of that duplication, I'm wondering if we who have already written the initial logic might want to take the next step and provide an
autocorrect
option for each rule. Or it could even be another "severity" number: 0 = ignore, 1 = warn, 2 = err, 3 = autocorrect. We could integrateautocorrect
features gradually, and only on rules where it could be done accurately.I do think the reaction "That should be a separate tool" makes some sense; but because so much of the core logic & problem solving would be duplicated, I don't know if the pure module-separation strategy would be worthwhile in this case.
Thoughts?
The text was updated successfully, but these errors were encountered: