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 meta.docs for each rule #246

Merged
merged 16 commits into from Jul 1, 2021
Merged

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

No description provided.

Loxos and others added 6 commits June 30, 2021 14:01
Eslint does support a documentation section in rule definitions. This section allows IDE plugins to display rule descriptions and directly link to the rule documentation. Details are documentad at: https://eslint.org/docs/developer-guide/working-with-rules#rule-basics
docs: {
description: '"if ... else if" constructs should end with "else" clauses',
category: 'Best Practices',
recommended: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be off to be consistent with index.ts?
Can we rely on this value from docs when creating profile in index.ts? So that it's not duplicated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should it be off to be consistent with index.ts?

No, it shouldn't unfortunately. Here is the type of the recommended property.

Can we rely on this value from docs when creating profile in index.ts? So that it's not duplicated

Yes, we can. I will do that.

category: 'Possible Errors',
recommended: 'error',
url: 'https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collection-size-mischeck.md',
requiresTypeChecking: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't find the doc for this property. Do you know where is it coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's coming from typescript-eslint (see Rule.ts). After looking at how it is used, we don't need it.

@@ -27,6 +27,12 @@ import { report, issueLocation } from '../utils/locations';
const rule: Rule.RuleModule = {
meta: {
type: 'suggestion',
docs: {
description: 'Collapsible "if" statements should be merged',
category: 'Stylistic Issues',
Copy link
Contributor

Choose a reason for hiding this comment

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

I would replace all Stylistic Issues rules in this PR with Best Practices. Stylistic Issues seems to be more about formatting.
We already have type property, so I would map suggestion to Best Practices and problem to Possible Errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I like this mapping you are suggesting.

@@ -44,5 +44,6 @@ it('should document all rules', () => {
existingRules.forEach(rule => {
expect(README.includes(rule)).toBe(true);
expect(fs.existsSync(`${root}/docs/rules/${rule}.md`)).toBe(true);
expect(rules[rule].meta.docs).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to assert that properties of docs are also defined and have specific values (to avoid typos)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think relying on the type system is enough here; it won't compile if there are any missing properties or if they don't have expected values.

@yassin-kammoun-sonarsource
Copy link
Contributor Author

Should we just rely on the file system to get the rule names ? WDYT ?

const sonarjsRules: string[] = [
'cognitive-complexity',
'elseif-without-else',
'generator-without-yield',
'max-switch-cases',
'no-all-duplicated-branches',
'no-collapsible-if',

description: 'Collapsible "if" statements should be merged',
category: 'Best Practices',
recommended: 'error',
url: docsUrl('o-collapsible-if'),
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

sonarjsRules.forEach(rule => (sonarjsRuleModules[rule[0]] = require(`./rules/${rule[0]}`)));
sonarjsRules.forEach(rule => (configs.recommended.rules![`sonarjs/${rule[0]}`] = rule[1]));
sonarjsRules.forEach(rule => (sonarjsRuleModules[rule] = require(`./rules/${rule}`)));
sonarjsRules.forEach(rule => {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this forEach has a full body now, we probably can merge it with the previous one

@vilchik-elena
Copy link
Contributor

@yassin-kammoun-sonarsource yeah, that makes sense so adding a new rule will be easier. Also we could rely on __filename when calling docUrl

@sonarcloud
Copy link

sonarcloud bot commented Jul 1, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@yassin-kammoun-sonarsource yassin-kammoun-sonarsource merged commit 6e95742 into master Jul 1, 2021
@yassin-kammoun-sonarsource yassin-kammoun-sonarsource deleted the yassin/meta-docs branch July 1, 2021 11:24
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

3 participants