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 --verbose flag #415

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

add --verbose flag #415

wants to merge 8 commits into from

Conversation

MFTabriz
Copy link
Contributor

@MFTabriz MFTabriz commented Jul 31, 2023

--verbose flag can be used to ensure linter is actually parsing the files when using globs or for general debugging.

PS: I couldn’t think of a simple solution to logs the relevant messages after each file’s name.

@MFTabriz MFTabriz marked this pull request as ready for review July 31, 2023 21:32
@MFTabriz
Copy link
Contributor Author

MFTabriz commented Jul 31, 2023

The failing test (failing to parse error message on windows) seems to be unrelated to this PR. It is the same issue which is blocking the dependabot.

@MFTabriz
Copy link
Contributor Author

MFTabriz commented Jul 31, 2023

I think I also fixed the path issue on windows!

@DavidAnson
Copy link
Collaborator

Do you mind applying that test path fix to the pending Dependabot PR? It should pass after that and I'll accept the PR.

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.

Just a tiny change request and also one thing to think about: Is "verbose" the right name for this flag? It's not wrong but it's also pretty specific about reporting "progress" - so is something like that maybe better?

markdownlint.js Outdated Show resolved Hide resolved
@DavidAnson
Copy link
Collaborator

Appreciate the tests, BTW!

@MFTabriz MFTabriz marked this pull request as draft July 31, 2023 23:13
@DavidAnson
Copy link
Collaborator

Looks good - tho I can't merge it because it's a Draft PR?

@MFTabriz
Copy link
Contributor Author

MFTabriz commented Aug 1, 2023

Looks good - tho I can't merge it because it's a Draft PR?

Thanks for your quick feedback and helps. I'm trying an idea (and simultaneously learning a bit of JS). I'll finalize this in a couple of days.

@DavidAnson
Copy link
Collaborator

I'm not sure there's a lot of room to improve upon what you have here, but I will keep an open mind until I see what you're up to. :)

meisam added 3 commits August 1, 2023 23:44
file names given to and received the library are logged independently
linters’s success messages are logged to stdout and fail to stderr
@MFTabriz
Copy link
Contributor Author

MFTabriz commented Aug 3, 2023

@DavidAnson Thanks for keeping an open mind. 😄I hope you are not allergic to bad JS codes!

Now the --verbose flag:

  • logs version
  • logs the list of the files given to the linter and the list of files reported back separately
  • respects --quiet and --output

As you already know, I’m not familiar with idiomatic JS. I’ll appreciate if you can guide me to improve this PR.

@MFTabriz MFTabriz marked this pull request as ready for review August 3, 2023 19:10
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.

OK, I see what you're going for and it makes sense in the context of what I've seen from other tools! However, the new behavior raises some more questions and I've left new comments. I will need to look at this again on a bigger screen than my phone, but I think this captures all the significant feedback. Thank you!

.option('--enable [rules...]', 'Enable certain rules, e.g. --enable MD013 MD041 --')
.option('--disable [rules...]', 'Disable certain rules, e.g. --disable MD013 MD041 --');

program.parse(process.argv);

if (options.quiet && options.verbose) {
options.verbose = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes me feel like it's one setting with three values?

@@ -256,6 +291,9 @@ const files = prepareFileList(program.args, ['md', 'markdown']).filter(value =>
const ignores = prepareFileList(options.ignore, ['md', 'markdown'], files);
const customRules = loadCustomRules(options.rules);
const diff = files.filter(file => !ignores.some(ignore => ignore.absolute === file.absolute)).map(paths => paths.original);
if (options.verbose && !options.stdin) {
console.log('files to check:', diff.join(' '));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be all on the same line? That is harder to scan visually.

@@ -299,6 +337,10 @@ function lintAndPrint(stdin, files) {
const fixResult = markdownlint.sync(fixOptions);
const fixes = fixResult[file].filter(error => error.fixInfo);
if (fixes.length > 0) {
if (options.verbose && !options.output) {
console.log('fixing', file);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there is a colon above, let's use one here also.

})
);
.filter(Boolean);

let lintResultString = '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of keeping this, I think it can be removed and recreated if it is needed. It looks like it is empty exactly when the strings array has no elements?

// @see {@link https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_exit_code}
// @see {@link https://github.com/igorshubovych/markdownlint-cli/pull/29#issuecomment-343535291}
process.exitCode = exitCodes.lintFindings;
return `${result.file}: ✔`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect failing files to end with a little 'x'?

t.is(result.exitCode, 0);
});

test('--verbose flag with --fix for incorrect file', async t => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing test for verbose with broken file (no fix).

t.is(result.exitCode, 0);
});

test('--output and --verbose with valid input logs nothing to console', async t => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could argue that verbose should always mean "verbose to console". If so, these two test cases would not be different. Just like I don't like how quiet and verbose overlap, disabling verbose for output seems not obvious?

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.

None yet

2 participants