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

Improve behaviour for invalid CLI options #3622

Merged
merged 3 commits into from Sep 24, 2018

Conversation

4 participants
@ybiquitous
Member

ybiquitous commented Aug 27, 2018

This change displays the user-friendly message(s) instead of help when invalid options are given.

For example:

$ stylelint --foo
Invalid option "--foo". Did you mean "--fix"?

image

Change summary:

  • Add package: leven
  • Add utility method: checkInvalidCLIOptions()

Which issue, if any, is this issue related to?

Closes #3602

Is there anything in the PR that needs further explanation?

No, it's self explanatory.

@@ -14,6 +15,8 @@ const printConfig = require("./printConfig");
const resolveFrom = require("resolve-from");
const standalone = require("./standalone");
const EXIT_CODE_ERROR = 2;

This comment has been minimized.

@ybiquitous

ybiquitous Aug 27, 2018

Member

Avoid magic numbers.

@@ -197,7 +200,7 @@ const meowOptions /*: meowOptionsType*/ = {
path can be absolute or relative to process.cwd(). By default, stylelint
looks for .stylelintignore in process.cwd().
--ignore-pattern, -ip
--ignore-pattern, --ip

This comment has been minimized.

@ybiquitous

ybiquitous Aug 27, 2018

Member

Maybe help bug. 😏

@ybiquitous ybiquitous force-pushed the ybiquitous:handle-invalid-cli-options branch from 36fa76d to d327bba Aug 27, 2018

@jeddy3

jeddy3 approved these changes Sep 6, 2018

@ybiquitous Thanks is great, thanks!

I hadn't heard of the Levenshtein distance algorithm before.

@ybiquitous

This comment has been minimized.

Member

ybiquitous commented Sep 7, 2018

@jeddy3 Thanks!

About shortcut options such as -f, suggestion accuracy seems not good to me... 🤔
(Perhaps it is better to stop suggestion for shortcut options?)

@jeddy3

This comment has been minimized.

Member

jeddy3 commented Sep 7, 2018

(Perhaps it is better to stop suggestion for shortcut options?)

SGTM. Even with just the non-shortcut suggestions, this is a great improvement. We can revisit an approach to shortcuts later down the line.

Do you want to update this PR?

@ybiquitous

This comment has been minimized.

Member

ybiquitous commented Sep 7, 2018

Do you want to update this PR?

Yes. I want to stop suggestion for shortcuts.

suggestion = all.find(option => leven(option, invalid) <= 3);
}
return suggestion;
};

This comment has been minimized.

@ybiquitous

ybiquitous Sep 7, 2018

Member

This suggest algorithm seems not good to me... 😓

$ ./bin/stylelint.js --hel
Invalid option "--hel". Did you mean "-h"?

Ideal

$ ./bin/stylelint.js --hel
Invalid option "--hel". Did you mean "--help"?

I will make this better 💪

This comment has been minimized.

@jeddy3

jeddy3 Sep 7, 2018

Member

Yep, the latter is better.

@ybiquitous

This comment has been minimized.

Member

ybiquitous commented Sep 7, 2018

I made some improvements via commit a3e96e7 😃

  • No suggestion for shortcut options
  • Better suggestion algorithm
@ybiquitous

This comment has been minimized.

@hudochenkov

This comment has been minimized.

Member

hudochenkov commented Sep 7, 2018

@ybiquitous no one knows we it's happening from time to time. We have some problems with ignoring parts of stylelint.

I restarted the build. It usually helps. I believe you can also restart it yourself next time if you sign in to AppVeyor with your Github account.

@ybiquitous

This comment has been minimized.

Member

ybiquitous commented Sep 7, 2018

Thanks a lot!

@jeddy3 jeddy3 referenced this pull request Sep 9, 2018

Closed

Release 9.6.0 #3638

4 of 4 tasks complete

ybiquitous added some commits Aug 27, 2018

Improve behaviour for invalid CLI options
This change displays user-friendly message(s) instead of help when invalid options are given.

For example:

```
$ stylelint --foo
Invalid option "--foo". Did you mean "--fix"?
```

Change summary:

- Add package: [`leven`](https://github.com/sindresorhus/leven)
- Add utility method: `checkInvalidCLIOptions()`

@ybiquitous ybiquitous force-pushed the ybiquitous:handle-invalid-cli-options branch from a3e96e7 to e65d513 Sep 11, 2018

@ntwb

ntwb approved these changes Sep 20, 2018

@jeddy3 jeddy3 merged commit e46b9df into stylelint:master Sep 24, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.006%) to 96.355%
Details
@jeddy3

This comment has been minimized.

Member

jeddy3 commented Sep 24, 2018

  • Added: suggestions for invalid CLI options (#3622).

@ybiquitous ybiquitous deleted the ybiquitous:handle-invalid-cli-options branch Sep 24, 2018

@ybiquitous

This comment has been minimized.

Member

ybiquitous commented Sep 24, 2018

@jeddy3 Thanks a lot! I am looking forward to the next release! 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment