Permalink
Cannot retrieve contributors at this time
54 lines (47 sloc)
1.92 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-jsx-a11y/__tests__/src/rules/tabindex-no-positive-test.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview Enforce tabIndex value is not greater than zero. | |
* @author Ethan Cohen | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/tabindex-no-positive'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'Avoid positive integer values for tabIndex.', | |
type: 'JSXAttribute', | |
}; | |
ruleTester.run('tabindex-no-positive', rule, { | |
valid: [ | |
{ code: '<div />;' }, | |
{ code: '<div {...props} />' }, | |
{ code: '<div id="main" />' }, | |
{ code: '<div tabIndex={undefined} />' }, | |
{ code: '<div tabIndex={`${undefined}`} />' }, | |
{ code: '<div tabIndex={`${undefined}${undefined}`} />' }, | |
{ code: '<div tabIndex={0} />' }, | |
{ code: '<div tabIndex={-1} />' }, | |
{ code: '<div tabIndex={null} />' }, | |
{ code: '<div tabIndex={bar()} />' }, | |
{ code: '<div tabIndex={bar} />' }, | |
{ code: '<div tabIndex={"foobar"} />' }, | |
{ code: '<div tabIndex="0" />' }, | |
{ code: '<div tabIndex="-1" />' }, | |
{ code: '<div tabIndex="-5" />' }, | |
{ code: '<div tabIndex="-5.5" />' }, | |
{ code: '<div tabIndex={-5.5} />' }, | |
{ code: '<div tabIndex={-5} />' }, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ code: '<div tabIndex="1" />', errors: [expectedError] }, | |
{ code: '<div tabIndex={1} />', errors: [expectedError] }, | |
{ code: '<div tabIndex={"1"} />', errors: [expectedError] }, | |
{ code: '<div tabIndex={`1`} />', errors: [expectedError] }, | |
{ code: '<div tabIndex={1.589} />', errors: [expectedError] }, | |
].map(parserOptionsMapper), | |
}); |