Skip to content

Commit

Permalink
JS-284 Rule parameter schema should be available statically in meta f…
Browse files Browse the repository at this point in the history
…ile (#4772)
  • Loading branch information
vdiez authored Aug 23, 2024
1 parent 76e7e89 commit 61f09d4
Show file tree
Hide file tree
Showing 1,003 changed files with 12,452 additions and 4,860 deletions.
9 changes: 0 additions & 9 deletions packages/jsts/src/rules/S100/meta.json

This file was deleted.

50 changes: 50 additions & 0 deletions packages/jsts/src/rules/S100/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

// DO NOT EDIT! This file is autogenerated by "npm run generate-meta"

export const meta = {
type: 'suggestion',
docs: {
description: 'Function and method names should comply with a naming convention',
recommended: false,
url: 'https://sonarsource.github.io/rspec/#/rspec/S100/javascript',
requiresTypeChecking: false,
},
};

export const sonarKey = 'S100';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
export const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
format: {
type: 'string',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;
22 changes: 2 additions & 20 deletions packages/jsts/src/rules/S100/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { Rule } from 'eslint';
import * as estree from 'estree';
import { functionLike, generateMeta, last } from '../helpers';
import { FromSchema } from 'json-schema-to-ts';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
import rspecMeta from './meta.json';
import { meta, schema } from './meta';

interface FunctionKnowledge {
node: estree.Identifier;
Expand Down Expand Up @@ -61,25 +60,8 @@ const messages = {
"Rename this '{{function}}' function to match the regular expression '{{format}}'.",
};

const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
format: {
type: 'string',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;

export const rule: Rule.RuleModule = {
meta: generateMeta(rspecMeta as Rule.RuleMetaData, { messages, schema }),
meta: generateMeta(meta as Rule.RuleMetaData, { messages, schema }),
create(context: Rule.RuleContext) {
const format = (context.options as FromSchema<typeof schema>)[0]?.format ?? DEFAULT_FORMAT;
const knowledgeStack: FunctionKnowledge[] = [];
Expand Down
9 changes: 0 additions & 9 deletions packages/jsts/src/rules/S101/meta.json

This file was deleted.

50 changes: 50 additions & 0 deletions packages/jsts/src/rules/S101/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

// DO NOT EDIT! This file is autogenerated by "npm run generate-meta"

export const meta = {
type: 'suggestion',
docs: {
description: 'Class names should comply with a naming convention',
recommended: true,
url: 'https://sonarsource.github.io/rspec/#/rspec/S101/javascript',
requiresTypeChecking: false,
},
};

export const sonarKey = 'S101';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
export const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
format: {
type: 'string',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;
22 changes: 2 additions & 20 deletions packages/jsts/src/rules/S101/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import { Rule } from 'eslint';
import * as estree from 'estree';
import { TSESTree } from '@typescript-eslint/utils';
import { generateMeta } from '../helpers';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
import { FromSchema } from 'json-schema-to-ts';
import rspecMeta from './meta.json';
import { meta, schema } from './meta';

type ClassOrInterfaceDeclaration = TSESTree.ClassDeclaration | TSESTree.TSInterfaceDeclaration;

Expand All @@ -34,25 +33,8 @@ const messages = {
renameClass: 'Rename {{symbolType}} "{{symbol}}" to match the regular expression {{format}}.',
};

const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
format: {
type: 'string',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;

export const rule: Rule.RuleModule = {
meta: generateMeta(rspecMeta as Rule.RuleMetaData, { messages, schema }),
meta: generateMeta(meta as Rule.RuleMetaData, { messages, schema }),
create(context: Rule.RuleContext) {
return {
ClassDeclaration: (node: estree.Node) =>
Expand Down
9 changes: 0 additions & 9 deletions packages/jsts/src/rules/S104/meta.json

This file was deleted.

50 changes: 50 additions & 0 deletions packages/jsts/src/rules/S104/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

// DO NOT EDIT! This file is autogenerated by "npm run generate-meta"

export const meta = {
type: 'suggestion',
docs: {
description: 'Files should not have too many lines of code',
recommended: false,
url: 'https://sonarsource.github.io/rspec/#/rspec/S104/javascript',
requiresTypeChecking: false,
},
};

export const sonarKey = 'S104';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
export const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
maximum: {
type: 'integer',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;
27 changes: 2 additions & 25 deletions packages/jsts/src/rules/S104/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,19 @@
import { Rule } from 'eslint';
import * as estree from 'estree';
import { getCommentLineNumbers, getLocsNumber } from '../S138/rule';
import { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
import { generateMeta } from '../helpers';
import { FromSchema } from 'json-schema-to-ts';
import rspecMeta from './meta.json';
import { meta, schema } from './meta';

const DEFAULT = 1000;
export type Options = [
{
maximum: number;
},
];

const schema = {
type: 'array',
minItems: 0,
maxItems: 1,
items: [
{
type: 'object',
properties: {
maximum: {
type: 'integer',
},
},
additionalProperties: false,
},
],
} as const satisfies JSONSchema4;

const messages = {
maxFileLine:
'This file has {{lineCount}} lines, which is greater than {{threshold}} authorized. Split it into smaller files.',
};

export const rule: Rule.RuleModule = {
meta: generateMeta(rspecMeta as Rule.RuleMetaData, { messages, schema }),
meta: generateMeta(meta as Rule.RuleMetaData, { messages, schema }),
create(context: Rule.RuleContext) {
const threshold = (context.options as FromSchema<typeof schema>)[0]?.maximum ?? DEFAULT;

Expand Down
11 changes: 3 additions & 8 deletions packages/jsts/src/rules/S104/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
*/
import { RuleTester } from 'eslint';
import { rule } from './';
import type { Options } from './rule';

const createOptions = (maximum: number): Options => {
return [{ maximum }];
};

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
ruleTester.run('Too many lines in file', rule, {
Expand All @@ -32,15 +27,15 @@ ruleTester.run('Too many lines in file', rule, {
code: `a;
b;
c;`,
options: createOptions(3),
options: [{ maximum: 3 }],
},
{
code: `a;
b;
// comment
c;`,
options: createOptions(3),
options: [{ maximum: 3 }],
},
],
invalid: [
Expand All @@ -51,7 +46,7 @@ ruleTester.run('Too many lines in file', rule, {
c;
// comment
d;`,
options: createOptions(3),
options: [{ maximum: 3 }],
errors: [
{
message: `This file has 4 lines, which is greater than 3 authorized. Split it into smaller files.`,
Expand Down
10 changes: 0 additions & 10 deletions packages/jsts/src/rules/S105/meta.json

This file was deleted.

34 changes: 34 additions & 0 deletions packages/jsts/src/rules/S105/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

// DO NOT EDIT! This file is autogenerated by "npm run generate-meta"

export const meta = {
type: 'suggestion',
docs: {
description: 'Tabulation characters should not be used',
recommended: false,
url: 'https://sonarsource.github.io/rspec/#/rspec/S105/javascript',
requiresTypeChecking: false,
},
deprecated: true,
};

export const sonarKey = 'S105';
Loading

0 comments on commit 61f09d4

Please sign in to comment.