Skip to content

Commit

Permalink
Fix message in S6844 (#4398)
Browse files Browse the repository at this point in the history
Co-authored-by: Yassin Kammoun <[email protected]>
  • Loading branch information
saberduck and yassin-kammoun-sonarsource authored Nov 17, 2023
1 parent a1e053d commit f992fc1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/jsts/src/rules/S6844/cb.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

<a href="javascript:void(0)" onClick={foo}>Perform action</a>; // Noncompliant {{Anchor used as a button. Anchors are primarily expected to navigate. Use the button element instead.}}

<a href="#" onClick={foo}>Perform action</a>; // Noncompliant

<a onClick={foo}>Perform action</a>; // Noncompliant

28 changes: 28 additions & 0 deletions packages/jsts/src/rules/S6844/cb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2023 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.
*/
import { check } from '../tools';
import { rule } from './';
import path from 'path';

const sonarId = path.basename(__dirname);

describe(`Rule ${sonarId}`, () => {
check(sonarId, rule, __dirname);
});
20 changes: 20 additions & 0 deletions packages/jsts/src/rules/S6844/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2023 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.
*/
export { rule } from './rule';
32 changes: 32 additions & 0 deletions packages/jsts/src/rules/S6844/rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2023 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.
*/
// https://sonarsource.github.io/rspec/#/rspec/S6844/javascript

import { rules as jsxA11yRules } from 'eslint-plugin-jsx-a11y';
import { interceptReport } from '../helpers';

const anchorIsValid = jsxA11yRules['anchor-is-valid'];

export const rule = interceptReport(anchorIsValid, (context, reportDescriptor) => {
const descriptor = reportDescriptor as any;
const { message } = descriptor;
descriptor.message = message.substring(0, message.indexOf(' Learn'));
context.report(descriptor);
});
2 changes: 2 additions & 0 deletions packages/jsts/src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { Rule } from 'eslint';

import { rule as S2376 } from './S2376'; // accessor-pairs
import { rule as S6844 } from './S6844'; // anchor-is-valid
import { rule as S6827 } from './S6827'; // anchor-has-content
import { rule as S5850 } from './S5850'; // anchor-precedence
import { rule as S3782 } from './S3782'; // argument-type
Expand Down Expand Up @@ -301,6 +302,7 @@ import { rule as S4817 } from './S4817'; // xpath
const rules: { [key: string]: Rule.RuleModule } = {};

rules['accessor-pairs'] = S2376;
rules['anchor-is-valid'] = S6844;
rules['anchor-has-content'] = S6827;
rules['anchor-precedence'] = S5850;
rules['argument-type'] = S3782;
Expand Down

0 comments on commit f992fc1

Please sign in to comment.