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

Add --enable + --disable CLI flags #234

Merged
merged 5 commits into from Nov 16, 2021
Merged

Add --enable + --disable CLI flags #234

merged 5 commits into from Nov 16, 2021

Conversation

janosh
Copy link
Contributor

@janosh janosh commented Nov 13, 2021

Closes #214.

@DavidAnson
Copy link
Collaborator

Awesome, thank you!!

Some high-level thoughts:

  1. commander supports variadic options and using that here should simplify the code a tiny bit and be more consistent: https://github.com/tj/commander.js#variadic-option
  2. It would be nice to offer single letter options, but we are running out of letters and 'd' is already taken
  3. Please make sure the syntax in README exactly matches what the program outputs
  4. No tiny URLs, please, folks can visit the README if they have questions
  5. "// leave default values in place if rule is an object" is clever!
  6. I think I would prefer to have disable take precedence if a rule is both enabled and disabled at the same time
  7. Let's please document number 6 as well - there may not be room in the syntax but it would be good to mention this in the README to call and that command line choices override configuration files
  8. I like the tests you've added, could we have one also to validate what happens when the same rule is enabled and disabled
  9. There should probably also be a test to validate the implementation of number five above
  10. It would also be good to have a test that used the name of the rule to make sure that works as well (ex: "line-length")

@janosh
Copy link
Contributor Author

janosh commented Nov 14, 2021

@DavidAnson Thanks for the quick review. Great comments! I think I addressed all of them.

Two of the tests for --disable are failing locally though. Not sure what's happening. I may be misusing the variadic args but not sure how to fix. Perhaps you can spot the issue?

Copy link
Collaborator

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

README.md Show resolved Hide resolved
README.md Outdated
-j, --json write issues in json format
-o, --output [outputFile] write issues to file (no console)
-p, --ignore-path [file] path to file with ignore pattern(s)
-q, --quiet do not write issues to STDOUT
-r, --rules [file|directory|glob|package] custom rule files
-r, --rules [file|directory|glob|package] custom rule files (default: [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the word "include" here to be more clear now that we have enable/disable? "include custom rule files"

README.md Outdated Show resolved Hide resolved
test/test.js Outdated

test('--disable flag overrides --enable', async t => {
const result = await execa('../markdownlint.js',
['--enable', 'MD002', '--disable', 'MD002', '--config', 'default-false-config.yml', 'incorrect.md'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really careful, can you swap the order of enable/disable here? Making enable be last is even more likely to leave the rule enabled.

test/test.js Outdated
await execa('../markdownlint.js',
['--disable', 'MD014', 'incorrect.md'],
{stripFinalNewline: false});
// t.fail();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be commented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

test/test.js Outdated

try {
await execa('../markdownlint.js',
['--disable', 'MD014', 'incorrect.md'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test failure is due to incorrect.md being treated as part of the disable list. See https://github.com/tj/commander.js/blob/master/docs/options-taking-varying-arguments.md#alternative-put-options-last for one way to avoid this, tho "--" is also fine and maybe good to show here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried adding the -- in there before but it didn't help. Or rather it wasn't enough. Turns out, you also need to pass each rules as a separate string for them to parse into an array, i.e.

- ['--disable', 'MD014 MD014 MD022', '--', 'incorrect.md']
+ ['--disable', 'MD014', 'MD014', 'MD022', '--', 'incorrect.md']

Do you prefer separating rules with spaces or commas? Spaces avoids the need for a custom parsing function but has slightly worse usability imo.

Copy link
Collaborator

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

@DavidAnson DavidAnson merged commit 3182fa0 into igorshubovych:master Nov 16, 2021
@DavidAnson
Copy link
Collaborator

By the way, I just now saw notifications for your most recent comments and updates. Sorry about seeming to ignore them, that wasn't the intent!

@janosh janosh deleted the cli-disable-flag branch November 16, 2021 07:17
@janosh
Copy link
Contributor Author

janosh commented Nov 16, 2021

@DavidAnson No problem. Do you know when the next release might land?

@DavidAnson
Copy link
Collaborator

Soon. I did some preparation work last night. :)

janosh added a commit to janosh/awesome-sveltekit that referenced this pull request Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable rules from CLI, not config file?
2 participants