diff --git a/packages/jsts/src/rules/S1067/rule.ts b/packages/jsts/src/rules/S1067/rule.ts index 5179ac847ab..2f89f95f1be 100644 --- a/packages/jsts/src/rules/S1067/rule.ts +++ b/packages/jsts/src/rules/S1067/rule.ts @@ -30,7 +30,6 @@ export type Options = [ { max: number; }, - string?, ]; export const rule: RuleModule = { diff --git a/packages/jsts/src/rules/S107/rule.ts b/packages/jsts/src/rules/S107/rule.ts index d6f448c4bcb..6ce1af42fda 100644 --- a/packages/jsts/src/rules/S107/rule.ts +++ b/packages/jsts/src/rules/S107/rule.ts @@ -62,7 +62,7 @@ export const rule: RuleModule = { const ruleDecoration: Rule.RuleModule = interceptReport( eslintMaxParams, function (context: Rule.RuleContext, descriptor: Rule.ReportDescriptor) { - const maxParams = (context.options as Options)[0].maximumFunctionParameters; + const [{ maximumFunctionParameters }] = context.options as Options; if ('node' in descriptor) { const functionLike = descriptor.node as TSESTree.FunctionLike; if (!isException(functionLike)) { @@ -76,7 +76,8 @@ export const rule: RuleModule = { function isBeyondMaxParams(functionLike: TSESTree.FunctionLike) { return ( - functionLike.params.filter(p => p.type !== 'TSParameterProperty').length <= maxParams + functionLike.params.filter(p => p.type !== 'TSParameterProperty').length <= + maximumFunctionParameters ); } diff --git a/packages/jsts/src/rules/S124/rule.ts b/packages/jsts/src/rules/S124/rule.ts index cd549d5b0bc..79b6b09ec22 100644 --- a/packages/jsts/src/rules/S124/rule.ts +++ b/packages/jsts/src/rules/S124/rule.ts @@ -47,7 +47,6 @@ export const rule: RuleModule = { type: 'string', }, }, - additionalProperties: false, }, ], }, diff --git a/packages/jsts/src/rules/S1541/rule.ts b/packages/jsts/src/rules/S1541/rule.ts index 11a3b24d8fc..06f92a9c21b 100644 --- a/packages/jsts/src/rules/S1541/rule.ts +++ b/packages/jsts/src/rules/S1541/rule.ts @@ -36,7 +36,6 @@ export type Options = [ { threshold: number; }, - string?, ]; export const rule: RuleModule = { @@ -58,8 +57,7 @@ export const rule: RuleModule = { ], }, create(context: Rule.RuleContext) { - const options = context.options as Options; - const threshold = options[0].threshold; + const [{ threshold }] = context.options as Options; let functionsWithParent: Map; let functionsDefiningModule: estree.Node[]; let functionsImmediatelyInvoked: estree.Node[]; diff --git a/packages/jsts/src/rules/S3524/rule.ts b/packages/jsts/src/rules/S3524/rule.ts index 868537f4917..c64f5e5fd96 100644 --- a/packages/jsts/src/rules/S3524/rule.ts +++ b/packages/jsts/src/rules/S3524/rule.ts @@ -49,7 +49,6 @@ export const rule: RuleModule = { type: 'boolean', }, }, - additionalProperties: false, }, ], }, diff --git a/packages/shared/src/types/rule.ts b/packages/shared/src/types/rule.ts index f09a33d5759..fdf9462cfc4 100644 --- a/packages/shared/src/types/rule.ts +++ b/packages/shared/src/types/rule.ts @@ -18,38 +18,29 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { type Rule } from 'eslint'; - -type Schemas = Extract>; -type Schema = Schemas[number]; +import { SONAR_RUNTIME } from '../../../jsts/src/linter/parameters'; +import { JSONSchema } from '@typescript-eslint/utils'; type BaseRuleModule = Omit; +type SonarRuntime = typeof SONAR_RUNTIME; +type RuleOptions = [Record, SonarRuntime?] | [SonarRuntime]; -type TypedJSONSchema, string?]> = Omit< - Schema, - 'type' | 'properties' -> & - Schema['properties'] & - ( - | { - type: 'object'; - properties: { [key in keyof Options[0]]: Schema }; - } - | { - type: 'string'; - enum: Array; - } - ); +type RuleModuleSchema = + | { + type: 'object'; + properties: { [key in keyof Options[0]]: JSONSchema.JSONSchema4 }; + } + | { + type: 'string'; + enum: Array; + }; -type RuleMetaData, string?]> = Omit< - Rule.RuleMetaData, - 'schema' -> & { - schema: Array>; +type RuleMetaData = Omit & { + schema: Array>; }; -export type RuleModule, string?] | null = null> = - Options extends [Record, string?] - ? Omit & { - meta: RuleMetaData; - } - : BaseRuleModule; +export type RuleModule = Options extends RuleOptions + ? Omit & { + meta: RuleMetaData; + } + : BaseRuleModule; diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CyclomaticComplexityTypeScriptCheck.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CyclomaticComplexityTypeScriptCheck.java index b382c7485c8..afd0984d84e 100644 --- a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CyclomaticComplexityTypeScriptCheck.java +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CyclomaticComplexityTypeScriptCheck.java @@ -19,43 +19,11 @@ */ package org.sonar.javascript.checks; -import java.util.Collections; -import java.util.List; import org.sonar.check.Rule; -import org.sonar.check.RuleProperty; -import org.sonar.plugins.javascript.api.EslintBasedCheck; import org.sonar.plugins.javascript.api.TypeScriptRule; @TypeScriptRule @Rule(key = "S1541") -public class CyclomaticComplexityTypeScriptCheck implements EslintBasedCheck { +public class CyclomaticComplexityTypeScriptCheck extends CyclomaticComplexityJavaScriptCheck { - private static final int DEFAULT_THRESHOLD = 10; - - @RuleProperty( - key = "Threshold", - description = "The maximum authorized complexity.", - defaultValue = "" + DEFAULT_THRESHOLD - ) - int threshold = DEFAULT_THRESHOLD; - - @Override - public List configurations() { - return Collections.singletonList( - new Config(this.threshold) - ); - } - @Override - public String eslintKey() { - return "cyclomatic-complexity"; - } - - private static class Config { - - int threshold; - - Config(int threshold) { - this.threshold = threshold; - } - } } diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/GetterSetterCheck.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/GetterSetterCheck.java index ef43318b57b..e14a2b95160 100644 --- a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/GetterSetterCheck.java +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/GetterSetterCheck.java @@ -44,7 +44,7 @@ public class GetterSetterCheck implements EslintBasedCheck { @Override public List configurations() { return Collections.singletonList( - new Config(getWithoutSet) + new Config(this.getWithoutSet) ); } diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/HardcodedCredentialsCheck.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/HardcodedCredentialsCheck.java index aa97d34bef4..82dbf87f334 100644 --- a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/HardcodedCredentialsCheck.java +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/HardcodedCredentialsCheck.java @@ -45,7 +45,7 @@ public class HardcodedCredentialsCheck implements EslintBasedCheck { @Override public List configurations() { return Collections.singletonList( - new Config(credentialWords.split("\\s*,\\s*")) + new Config(this.credentialWords.split("\\s*,\\s*")) ); }