Skip to content

Commit

Permalink
Improve S6855 (media-has-caption): Report on the name of the openin…
Browse files Browse the repository at this point in the history
…g element (#4406)
  • Loading branch information
yassin-kammoun-sonarsource authored Nov 21, 2023
1 parent 8312fa5 commit 0d68574
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/jsts/src/rules/S6855/cb.fixture.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function MyVideo() {
return <video {...props} />; // Noncompliant
// ^^^^^
}
28 changes: 28 additions & 0 deletions packages/jsts/src/rules/S6855/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 S6855', () => {
check(sonarId, rule, __dirname);
});
33 changes: 33 additions & 0 deletions packages/jsts/src/rules/S6855/decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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/S6855/javascript

import { Rule } from 'eslint';
import { Node } from 'estree';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { interceptReport } from '../helpers';

export function decorate(rule: Rule.RuleModule): Rule.RuleModule {
return interceptReport(rule, (context, descriptor) => {
const { node } = descriptor as unknown as { node: TSESTree.JSXOpeningElement };
const name = node.name as unknown as Node;
context.report({ ...descriptor, node: name });
});
}
23 changes: 23 additions & 0 deletions packages/jsts/src/rules/S6855/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { rules as jsxA11yRules } from 'eslint-plugin-jsx-a11y';
import { decorate } from './decorator';

export const rule = decorate(jsxA11yRules['media-has-caption']);
2 changes: 2 additions & 0 deletions packages/jsts/src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import { rule as S6853 } from './S6853'; // label-has-associated-control
import { rule as S1439 } from './S1439'; // label-position
import { rule as S5148 } from './S5148'; // link-with-target-blank
import { rule as S4622 } from './S4622'; // max-union-size
import { rule as S6855 } from './S6855'; // media-has-caption
import { rule as S1994 } from './S1994'; // misplaced-loop-counter
import { rule as S1082 } from './S1082'; // mouse-events-a11y
import { rule as S134 } from './S134'; // nested-control-flow
Expand Down Expand Up @@ -401,6 +402,7 @@ rules['label-has-associated-control'] = S6853;
rules['label-position'] = S1439;
rules['link-with-target-blank'] = S5148;
rules['max-union-size'] = S4622;
rules['media-has-caption'] = S6855;
rules['misplaced-loop-counter'] = S1994;
rules['mouse-events-a11y'] = S1082;
rules['nested-control-flow'] = S134;
Expand Down

0 comments on commit 0d68574

Please sign in to comment.