Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions its/ruling/src/test/expected/TypeScript/typescript-S7728.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,5 @@
"TypeScript:src/harness/test262Runner.ts": [
113,
118
],
"TypeScript:src/services/formatting/rulesMap.ts": [
32,
46,
47
]
}
17 changes: 17 additions & 0 deletions packages/jsts/src/rules/S8463/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2025 SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* 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 Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
export { rule } from './rule.js';
19 changes: 19 additions & 0 deletions packages/jsts/src/rules/S8463/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2025 SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* 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 Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
// https://sonarsource.github.io/rspec/#/rspec/S8463/javascript
export const implementation = 'original';
export const eslintId = 'no-reserved-demo-identifiers';
52 changes: 52 additions & 0 deletions packages/jsts/src/rules/S8463/rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2025 SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* 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 Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
// https://sonarsource.github.io/rspec/#/rspec/S8463/javascript

import type { Rule } from 'eslint';
import { generateMeta } from '../helpers/index.js';
import type estree from 'estree';
import * as meta from './generated-meta.js';

const RESERVED_PREFIX = 'sonar_vibe_bot_will_flag_this';

export const rule: Rule.RuleModule = {
meta: generateMeta(meta, {
messages: {
reservedIdentifier: `Rename this identifier; names containing "${RESERVED_PREFIX}" are reserved for demo purposes and should not appear in production code.`,
},
}),
create(context: Rule.RuleContext) {
return {
FunctionDeclaration(node: estree.FunctionDeclaration) {
if (node.id && node.id.name.includes(RESERVED_PREFIX)) {
context.report({
node: node.id,
messageId: 'reservedIdentifier',
});
}
},
VariableDeclarator(node: estree.VariableDeclarator) {
if (node.id.type === 'Identifier' && node.id.name.includes(RESERVED_PREFIX)) {
context.report({
node: node.id,
messageId: 'reservedIdentifier',
});
}
},
};
},
};
92 changes: 92 additions & 0 deletions packages/jsts/src/rules/S8463/unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2025 SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* 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 Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
import { NoTypeCheckingRuleTester } from '../../../tests/tools/testers/rule-tester.js';
import { rule } from './index.js';
import { describe, it } from 'node:test';

describe('S8463', () => {
it('S8463', () => {
const ruleTester = new NoTypeCheckingRuleTester();

ruleTester.run('Reserved demo identifiers should not be used in production code', rule, {
valid: [
{
code: `function computeAnswer() { return 42; }`,
},
{
code: `const score = computeScore();`,
},
{
code: `let x = 1;`,
},
{
code: `var result = someFunction();`,
},
{
// String literal containing the reserved prefix is not flagged
code: `const msg = "sonar_vibe_bot_will_flag_this is a demo prefix";`,
},
{
// Comment mentioning the prefix is not flagged
code: `// sonar_vibe_bot_will_flag_this is only for demos`,
},
{
// Arrow function expression with normal name
code: `const compute = () => 42;`,
},
],
invalid: [
{
code: `function sonar_vibe_bot_will_flag_this_issue() { return 42; }`,
errors: [
{
message:
'Rename this identifier; names containing "sonar_vibe_bot_will_flag_this" are reserved for demo purposes and should not appear in production code.',
},
],
},
{
code: `const sonar_vibe_bot_will_flag_this_value = computeScore();`,
errors: 1,
},
{
code: `let sonar_vibe_bot_will_flag_this_count = 0;`,
errors: 1,
},
{
code: `var sonar_vibe_bot_will_flag_this_result = fetchData();`,
errors: 1,
},
{
// Exact prefix as the full name
code: `function sonar_vibe_bot_will_flag_this() {}`,
errors: 1,
},
{
// Prefix in the middle of a name
code: `const prefix_sonar_vibe_bot_will_flag_this_suffix = 1;`,
errors: 1,
},
{
// Multiple declarations in one statement
code: `const sonar_vibe_bot_will_flag_this_a = 1, sonar_vibe_bot_will_flag_this_b = 2;`,
errors: 2,
},
],
});
});
});
Loading