-
Notifications
You must be signed in to change notification settings - Fork 17
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
style(spec): add out-of-line-enum rule APIC-416 #356
Conversation
✅ Deploy Preview for api-clients-automation ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✗ The generated branch has been deleted.If the PR has been merged, you can check the generated code on the |
87040bd
to
9d77035
Compare
9d77035
to
2d36490
Compare
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.
Looks very good, I tested it locally and it seems to work fine !
} | ||
if ( | ||
isPairWithKey( | ||
node.parent.parent.parent.parent?.parent?.parent?.parent ?? null, |
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.
Is there any way to prevent that kind of path ?
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.
it's a very specific edge case that we want to solve here, it won't be used anywhere else but if we need to we can have a function that checks N parents above, I will add it if I ever encounter a parent chain I will add it !
yield fixer.replaceTextRange([end - 1, end], "'"); | ||
} else { | ||
yield fixer.insertTextBeforeRange([start, start], "'"); | ||
yield fixer.insertTextAfterRange([end, end], "'"); |
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'd check if the last character is not '
, otherwise it will escape the last you add ;) . (in the case it doesn't start with a quote but it ends with it)
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'm not sure if I saw it elsewhere but we also need to make sure the string does not contain a '
, if so we should fallback to double quoted
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.
pretty sure "
and '
are forbidden characters for path and yaml key, this is not a concern for this particular rule.
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.
Ah yes this is only for ref
s sorry I forgot I was thinking of description/summaries
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.
:very_nice:!!!
website/docs/specsCommands.md
Outdated
yarn specs:lint specs/ --fix | ||
``` | ||
|
||
If you just want to check the format (not override the files), run: | ||
|
||
```bash | ||
yarn specs:lint <client> | ||
yarn specs:lint search | ||
yarn specs:lint specs/<client> --fix | ||
yarn specs:lint specs/search --fix |
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.
The README
does not mention the --fix
, is that intended? Also, does it make sense to keep docs in a README since we have the same on the website?
package.json
Outdated
@@ -25,8 +25,7 @@ | |||
"release": "yarn workspace scripts createReleaseIssue", | |||
"scripts:lint": "eslint --ext=ts scripts/", | |||
"scripts:test": "yarn workspace scripts test", | |||
"specs:fix": "eslint --ext=yml specs/$0 --fix", | |||
"specs:lint": "eslint --ext=yml specs/$0", | |||
"specs:lint": "eslint --ext=yml", |
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.
much cleaner
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 those comments were made before the last commit, do you me to get back to only one specs:lint
script ?
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.
Ah true, I liked the idea so it's closer to the base eslint usage, but that's just my opinion.
} | ||
if ( | ||
isPairWithKey( | ||
node.parent.parent.parent.parent?.parent?.parent?.parent ?? null, |
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.
We can maybe have a function that will find the deepest parent in a given element, so it handles even deeper ones etc.
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.
Here it's not necessarily the deepest, it's just that's the 7th parent has be to a pair with key servers
, not sure if it generalizable.
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.
Yes but there should only be one servers
in a spec so we can maybe assume that the deepest or first found is correct?
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.
we could, but that won't make the code simpler so I don't see why change
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.
it was more to make sure if it's the 6th or 9th it won't require an other manual check, it's not necessary to change it right now, we can iterate on it if there's an issue one day
eslint/src/rules/singleQuoteRef.ts
Outdated
return; | ||
} | ||
if (!isScalar(node.value)) { | ||
// not our problem |
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.
can you elaborate why it's not?
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.
If the ref is not a scalar (not a string) then something else will fail, like the path resolution of redocly so we don't need to check here, I will comment.
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.
Yes I meant elaborate the comment, I get the reason :D
eslint/src/rules/singleQuoteRef.ts
Outdated
return; | ||
} | ||
if (isBLockScalar(node.value)) { | ||
// what to do here ? |
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.
Nothing
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.
well it could maybe work with block scalar I haven't tried it, but it should be forbidden by another rule because it doesn't make sense.
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.
yep definitely, I guess blocks can be as is it's fine
const hasDoubleQuote = node.value.style === 'double-quoted'; | ||
const [start, end] = node.value.range; | ||
context.report({ | ||
node: node as any, |
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.
how come we need to cast 🤔
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.
There is an issue between eslint type Node
and yaml-eslint-parser
type that inherits from the wrong Node
, so type are not compatible but in practice they have the same properties.
yield fixer.replaceTextRange([end - 1, end], "'"); | ||
} else { | ||
yield fixer.insertTextBeforeRange([start, start], "'"); | ||
yield fixer.insertTextAfterRange([end, end], "'"); |
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'm not sure if I saw it elsewhere but we also need to make sure the string does not contain a '
, if so we should fallback to double quoted
const spinner = createSpinner('linting common spec', verbose).start(); | ||
await run(`yarn specs:lint common`, { verbose }); |
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.
don't we want to fix when it's not the CI?
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'm not a fan of scripts modifying hand written file when it's unclear, but here it should be fine
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.
Make sense but if it's only for dev purposes it's fine I guess
(as you want)
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.
just so we remove bundled specs from the PR
specs/bundled/analytics.yml
Outdated
@@ -53,7 +53,7 @@ components: | |||
period to analyze. |
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.
bundled
specs changes are pushed by the CI
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.
ah yes sorry I forgot
…tomation into style/eslint-enum
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.
Pretty solid! Good addition ✍🏼
🧭 What and Why
🎟 JIRA Ticket: APIC-416
Add a rule to enforce out of line enum, except in
servers
section (not required here).Also disable this rule for the bundled specs, as some refs are deleted.
Also include the simple rule
ref-single-quote
that enforce single quote on all$ref
Changes included:
out-of-line-enum
ruleref-single-quote
rulecommon
specs with cache#357 contains the modification to the specs
🧪 Test
yarn docker build specs