Skip to content

Commit

Permalink
Update rules metadata (#4856)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez authored Sep 25, 2024
1 parent 35e38c6 commit 49be780
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 18 deletions.
2 changes: 1 addition & 1 deletion css-sonarpedia/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"languages": [
"CSS"
],
"latest-update": "2024-09-17T13:10:55.911474Z",
"latest-update": "2024-09-25T13:47:31.326757900Z",
"options": {
"no-language-in-filenames": true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jsts/src/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ If you are a [SonarQube](https://www.sonarqube.org) or [SonarCloud](https://sona
| [no-self-compare](https://sonarsource.github.io/rspec/#/rspec/S6679/javascript) | "Number.isNaN()" should be used to check for "NaN" value || | 💡 | | |
| [no-self-import](https://sonarsource.github.io/rspec/#/rspec/S7060/javascript) | Module should not import itself || | 💡 | | |
| [no-skipped-test](https://sonarsource.github.io/rspec/#/rspec/S1607/javascript) | Tests should not be skipped without providing a reason || | | | |
| [no-small-switch](https://sonarsource.github.io/rspec/#/rspec/S1301/javascript) | "switch" statements should have at least 3 "case" clauses || | | | |
| [no-small-switch](https://sonarsource.github.io/rspec/#/rspec/S1301/javascript) | "if" statements should be preferred over "switch" when simpler || | | | |
| [no-tab](https://sonarsource.github.io/rspec/#/rspec/S105/javascript) | Tabulation characters should not be used | | | | ||
| [no-table-as-layout](https://sonarsource.github.io/rspec/#/rspec/S5257/javascript) | HTML "<table>" should not be used for layout purposes || | | | |
| [no-this-alias](https://sonarsource.github.io/rspec/#/rspec/S4327/javascript) | "this" should not be assigned to variables | | | | | |
Expand Down
2 changes: 1 addition & 1 deletion packages/jsts/src/rules/S1301/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
export const meta = {
type: 'suggestion',
docs: {
description: '"switch" statements should have at least 3 "case" clauses',
description: '"if" statements should be preferred over "switch" when simpler',
recommended: true,
url: 'https://sonarsource.github.io/rspec/#/rspec/S1301/javascript',
requiresTypeChecking: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/jsts/src/rules/S1607/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import {
isLiteral,
isMethodInvocation,
resolveFunction,
toUnixPath,
} from '../helpers';
import { meta } from './meta';
import { TSESTree } from '@typescript-eslint/utils';
import fs from 'fs';
import { dirname } from 'path/posix';

export const rule: Rule.RuleModule = {
meta: generateMeta(meta as Rule.RuleMetaData, {
Expand All @@ -53,7 +54,7 @@ export const rule: Rule.RuleModule = {
return jestListener();
case dependencies.has('mocha'):
return mochaListener();
case getManifests(context.filename, context.cwd, fs).length > 0:
case getManifests(dirname(toUnixPath(context.filename)), context.cwd).length > 0:
return nodejsListener();
default:
return {};
Expand Down
1 change: 1 addition & 0 deletions packages/jsts/src/rules/S1607/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { RuleTester } from 'eslint';
import { rule } from './';

process.chdir(__dirname); // change current working dir to avoid the package.json lookup to up in the tree
const ruleTester = new RuleTester();

ruleTester.run(`Tests should not be skipped without providing a reason`, rule, {
Expand Down
5 changes: 3 additions & 2 deletions packages/jsts/src/rules/S6661/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import { Rule } from 'eslint';
import { eslintRules } from '../core';
import { decorate } from './decorator';
import { isSupported } from '../helpers/validate-version';
import { dirname } from 'path/posix';
import { toUnixPath, isSupported } from '../helpers';

const decorated = decorate(eslintRules['prefer-object-spread']);

export const rule: Rule.RuleModule = {
meta: decorated.meta,
create(context) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#browser_compatibility
if (!isSupported(context.filename, { node: '8.3.0' })) {
if (!isSupported(dirname(toUnixPath(context.filename)), { node: '8.3.0' })) {
return {};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/jsts/src/rules/S6957/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import { Rule } from 'eslint';
import { rules } from 'eslint-plugin-react';
import { generateMeta, getManifests } from '../helpers';
import { generateMeta, getManifests, toUnixPath } from '../helpers';
import { FromSchema } from 'json-schema-to-ts';
import { meta, schema } from './meta';
import path from 'path';
import { dirname } from 'path/posix';

const reactNoDeprecated = rules['no-deprecated'];

Expand All @@ -39,7 +39,7 @@ export const rule: Rule.RuleModule = {
return (context.options as FromSchema<typeof schema>)[0]?.['react-version'];
}
function getVersionFromPackageJson() {
for (const packageJson of getManifests(path.posix.dirname(context.filename))) {
for (const packageJson of getManifests(dirname(toUnixPath(context.filename)), context.cwd)) {
if (packageJson.dependencies?.react) {
return packageJson.dependencies.react;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/jsts/tests/analysis/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,10 @@ describe('analyzeJSTS', () => {
create(context) {
return {
CallExpression(node) {
const packageJsons = getManifests(path.posix.dirname(context.filename), baseDir);
const packageJsons = getManifests(
path.posix.dirname(toUnixPath(context.filename)),
baseDir,
);
expect(packageJsons).toBeDefined();
expect(packageJsons[0].name).toEqual('test-module');
context.report({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
546
]
},
"quickfix": "unknown",
"quickfix": "infeasible",
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"quickfix": "covered",
"status": "deprecated",
"tags": [],
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "FORMATTED"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ruleSpecification": "RSPEC-1479",
"sqKey": "S1479",
"scope": "Main",
"quickfix": "unknown",
"quickfix": "infeasible",
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S1537",
"scope": "Main",
"quickfix": "covered",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW"
},
"attribute": "FORMATTED"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ruleSpecification": "RSPEC-1871",
"sqKey": "S1871",
"scope": "Main",
"quickfix": "unknown",
"quickfix": "infeasible",
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"1.14.6"
]
},
"quickfix": "unknown",
"quickfix": "infeasible",
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
"ruleSpecification": "RSPEC-2260",
"sqKey": "S2260",
"scope": "Main",
"quickfix": "unknown",
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM",
"RELIABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S2310",
"scope": "Main",
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "CLEAR"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S3523",
"scope": "Main",
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S3723",
"scope": "Main",
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "FORMATTED"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ruleSpecification": "RSPEC-4144",
"sqKey": "S4144",
"scope": "Main",
"quickfix": "unknown",
"quickfix": "infeasible",
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ <h2>Why is this an issue?</h2>
address?: string;
}
</pre>
<p>The rule does not raise any issues when the TypeScript compiler option <code>exactOptionalPropertyTypes</code> is enabled because this option
ensures that <code>undefined</code> does not become redundant in this context.</p>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
<li> TypeScript Documentation - <a href="https://www.typescriptlang.org/docs/handbook/2/objects.html#optional-properties">Optional Properties</a>
</li>
<li> TypeScript Documentation - <a href="https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types">Union Types</a> </li>
<li> TypeScript Documentation - <a href="https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes">exactOptionalPropertyTypes</a> </li>
</ul>

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S6660",
"scope": "All",
"quickfix": "covered",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"sqKey": "S6661",
"scope": "All",
"quickfix": "covered",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S6666",
"scope": "All",
"quickfix": "covered",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S6671",
"scope": "All",
"quickfix": "infeasible",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S6676",
"scope": "All",
"quickfix": "covered",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"sqKey": "S6679",
"scope": "All",
"quickfix": "covered",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
Expand Down
2 changes: 1 addition & 1 deletion sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"languages": [
"JS"
],
"latest-update": "2024-09-17T13:10:19.300365Z",
"latest-update": "2024-09-25T13:47:06.983012100Z",
"options": {
"no-language-in-filenames": true,
"preserve-filenames": true
Expand Down

0 comments on commit 49be780

Please sign in to comment.