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 flaws check / fix to cli #1623

Merged
merged 4 commits into from
Nov 5, 2020
Merged

Add flaws check / fix to cli #1623

merged 4 commits into from
Nov 5, 2020

Conversation

fiji-flo
Copy link
Contributor

@fiji-flo fiji-flo commented Nov 3, 2020

  • add flaws check to validate
  • add flaws command

@fiji-flo fiji-flo requested review from escattone and peterbe November 3, 2020 12:48
@peterbe
Copy link
Contributor

peterbe commented Nov 3, 2020

What is the context here? When would you use this? Does it solve an issue we have?

@fiji-flo
Copy link
Contributor Author

fiji-flo commented Nov 3, 2020

The idea was to enable editors to fix flaws from the cli and add it to the validation.

Mostly parity with the UI though.

Copy link
Contributor

@peterbe peterbe left a comment

Choose a reason for hiding this comment

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

Works! Clearly...
Screen Shot 2020-11-03 at 2 01 47 PM

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);

@fiji-flo
Copy link
Contributor Author

fiji-flo commented Nov 4, 2020

I'd like to add some more capabilities to that command in the future. For now I think flaws is an okay name as it also just displays flaws and fixing is (kind of) optional. I get you suggestion to make it no only accept slugs but this should then change for all commands.

I filed mdn/rari#170 to follow up on this.

- add flaws check to validate
- add flaws command
@peterbe
Copy link
Contributor

peterbe commented Nov 4, 2020

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.
You still have my approval. Now we have to wait for @escattone

Copy link
Contributor

@escattone escattone left a 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"));
Copy link
Contributor

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));
Copy link
Contributor

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));
Copy link
Contributor

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
Comment on lines 265 to 272
const { run } = yes
? true
: await prompts({
type: "confirm",
message: `Proceed fixing ${flaws} flaws?`,
name: "run",
initial: true,
});
Copy link
Contributor

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:

Suggested change
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;

@fiji-flo
Copy link
Contributor Author

fiji-flo commented Nov 5, 2020

@escattone thanks for the feedback all should be addressed

@fiji-flo fiji-flo requested a review from escattone November 5, 2020 17:46
Copy link
Contributor

@escattone escattone left a 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!

@escattone
Copy link
Contributor

@fiji-flo If you don't mind, I'll just commit the tiny typo fixes and merge this. Thanks!

@escattone escattone merged commit 4ac5b55 into mdn:master Nov 5, 2020
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.

3 participants