-
Notifications
You must be signed in to change notification settings - Fork 526
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 flaws check / fix to cli #1623
Conversation
fiji-flo
commented
Nov 3, 2020
- add flaws check to validate
- add flaws command
What is the context here? When would you use this? Does it solve an issue we have? |
The idea was to enable editors to fix flaws from the cli and add it to the validation. Mostly parity with the UI though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd get the same effect/result if you visit http://localhost:3000/en-US/docs/Web/CSS/background-image#_flaws and press the "Fix fixable flaws (3)" button.
The only thing I don't like is that yarn tool flaws [slug]
feels like it would show the flaws or something. So it doesn't feel super intuitively named. Perhaps yarn tool fix-flaws [slug]
would make more sense.
But I welcome the functionality. Perhaps it ought to be documented too. Nit?
The other thing I'm not entirely sure about is if the slug
is the best entry for this. I think I'd rather be able to do:
▶ yarn tool flaws http://localhost:3000/en-US/docs/Web/CSS/background-image
or
▶ yarn tool flaws /en-US/docs/Web/CSS/background-image
But perhaps that's just me. And perhaps it would be somewhat trivial to hack around like this:
const { slug, locale } = args;
const { yes } = options;
let url;
if (slug.includes('://') || slug.startsWith('/')) {
if (slug.includes('://')) {
url = new URL(slug).pathname
} else {
url=slug;
}
} else {
url=buildURL(locale, slug)
}
const document = Document.findByURL(url);
I'd like to add some more capabilities to that command in the future. For now I think I filed mdn/rari#170 to follow up on this. |
- add flaws check to validate - add flaws command
Ok. Fair enough. I think this'll come in handy but only time will tell where our actual users gravitate and we won't know what for months. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fiji-flo I really like this! I think it needs to show a more user-friendly error message though when the user provides a slug that doesn't exist. Currently it shows Cannot destructure property 'metadata' of 'document' as it is undefined.
:
rjohnson-44864:deployer rjohnson$(maws_profile)$ yarn tool validate Web/ZZZ
yarn run v1.22.5
$ node tool/cli.js validate Web/ZZZ
Cannot destructure property 'metadata' of 'document' as it is undefined.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
rjohnson-44864:deployer rjohnson$(maws_profile)$ yarn tool flaws Web/ZZZ
yarn run v1.22.5
$ node tool/cli.js flaws Web/ZZZ
Cannot destructure property 'metadata' of 'document' as it is undefined.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
tool/cli.js
Outdated
if (okay) { | ||
console.log(chalk.green("✓ All seems fine")); | ||
} else { | ||
console.log(chalk.red("✗ Found some issues")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels redundant and a bit confusing to me (e.g., are issues different than flaws?), since before this message is shown, the user will see Found X flaws.
. For example:`
rjohnson-44864:deployer rjohnson$(maws_profile)$ yarn tool validate Web
yarn run v1.22.5
$ node tool/cli.js validate Web
Found 4 flaws.
✗ Found some issues
✨ Done in 1.28s.
Could we simply skip this message when okay
is falsy?
Document.validate(slug, locale); | ||
console.log(chalk.green("✓ All seems fine")); | ||
let okay = true; | ||
const document = Document.findByURL(buildURL(locale, slug)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to show a friendly error message when the document can't be found.
tryOrExit(async ({ args, options }) => { | ||
const { slug, locale } = args; | ||
const { yes } = options; | ||
const document = Document.findByURL(buildURL(locale, slug)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here, a friendly error message when the document can't be found.
tool/cli.js
Outdated
const { run } = yes | ||
? true | ||
: await prompts({ | ||
type: "confirm", | ||
message: `Proceed fixing ${flaws} flaws?`, | ||
name: "run", | ||
initial: true, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is broken when -y, --yes
is used on the command line:
rjohnson-44864:deployer rjohnson$(maws_profile)$ yarn tool flaws Web --yes
yarn run v1.22.5
$ node tool/cli.js flaws Web --yes
Would fix (link1) broken_link /en-US/docs/Web/Apps to /en-US/docs/Web/Progressive_web_apps
Would fix (link4) broken_link /en-US/docs/SVG to /en-US/docs/Web/SVG
Would modify "/Users/rjohnson/repos/content/files/en-us/web/index.html" from fixable flaws.
✨ Done in 1.30s.
Maybe something like:
const { run } = yes | |
? true | |
: await prompts({ | |
type: "confirm", | |
message: `Proceed fixing ${flaws} flaws?`, | |
name: "run", | |
initial: true, | |
}); | |
const run = yes | |
? true | |
: await prompts({ | |
type: "confirm", | |
message: `Proceed fixing ${flaws} flaws?`, | |
name: "run", | |
initial: true, | |
}).run; |
@escattone thanks for the feedback all should be addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Two tiny typos to fix before you merge. Thanks @fiji-flo!
@fiji-flo If you don't mind, I'll just commit the tiny typo fixes and merge this. Thanks! |