Skip to content

Commit 1d89064

Browse files
committed
[Refactor] this falsy condition is impossible in a rule, because JSXAttribute can’t ever have a falsy propName.
If it does in the future, then that would throw an error - which would surface the bug, instead of silently avoiding it.
1 parent b12f081 commit 1d89064

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

src/rules/aria-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
create: context => ({
3737
JSXAttribute: (attribute) => {
3838
const name = propName(attribute);
39-
const normalizedName = name ? name.toLowerCase() : '';
39+
const normalizedName = name.toLowerCase();
4040

4141
// `aria` needs to be prefix of property.
4242
if (normalizedName.indexOf('aria-') !== 0) {

src/rules/aria-proptypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = {
6363
create: context => ({
6464
JSXAttribute: (attribute) => {
6565
const name = propName(attribute);
66-
const normalizedName = name ? name.toLowerCase() : '';
66+
const normalizedName = name.toLowerCase();
6767

6868
// Not a valid aria-* state or property.
6969
if (normalizedName.indexOf('aria-') !== 0 || aria.get(normalizedName) === undefined) {

src/rules/aria-role.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ module.exports = {
4141
}
4242

4343
// Get prop name
44-
const name = propName(attribute);
45-
const normalizedName = name ? name.toUpperCase() : '';
44+
const name = propName(attribute).toUpperCase();
4645

47-
if (normalizedName !== 'ROLE') { return; }
46+
if (name !== 'ROLE') { return; }
4847

4948
const value = getLiteralPropValue(attribute);
5049

src/rules/aria-unsupported-elements.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ module.exports = {
4747
return;
4848
}
4949

50-
const name = propName(prop);
51-
const normalizedName = name ? name.toLowerCase() : '';
50+
const name = propName(prop).toLowerCase();
5251

53-
if (invalidAttributes.indexOf(normalizedName) > -1) {
52+
if (invalidAttributes.indexOf(name) > -1) {
5453
context.report({
5554
node,
5655
message: errorMessage(name),

src/rules/role-has-required-aria-props.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ module.exports = {
2626

2727
create: context => ({
2828
JSXAttribute: (attribute) => {
29-
const name = propName(attribute);
30-
const normalizedName = name ? name.toLowerCase() : '';
29+
const name = propName(attribute).toLowerCase();
3130

32-
if (normalizedName !== 'role') {
31+
if (name !== 'role') {
3332
return;
3433
}
3534

src/rules/tabindex-no-positive.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ module.exports = {
2222

2323
create: context => ({
2424
JSXAttribute: (attribute) => {
25-
const name = propName(attribute);
26-
const normalizedName = name ? name.toUpperCase() : '';
25+
const name = propName(attribute).toUpperCase();
2726

2827
// Check if tabIndex is the attribute
29-
if (normalizedName !== 'TABINDEX') {
28+
if (name !== 'TABINDEX') {
3029
return;
3130
}
3231

0 commit comments

Comments
 (0)