-
Notifications
You must be signed in to change notification settings - Fork 199
feat(rule): Add new rule - react-a11y-media-captions #850
Conversation
fix behavior of validateMediaType
@JoshuaKGoldberg @IllusionMH Hey guys, would like your review on this. |
@noamyogev84 thanks for PR, will try to review it this weekend. CI fails on Node 6, where npm does support |
@IllusionMH great, thanks man! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule code look good. Handles case that I've missed. 👍
However, two paths doesn't have failing and successful test, which will be really helpful.
Could you please rebase your branch, and then run npm install
and npm test
? There are some unexpected changes in tslint-warnings.csv
and new entry should be added to configs/latest.json
.
src/reactA11yMediaCaptionsRule.ts
Outdated
function getAttributeText(attribute: ts.JsxAttribute): string | undefined { | ||
if (attribute && attribute.initializer) { | ||
if (tsutils.isJsxExpression(attribute.initializer)) { | ||
return attribute.initializer.expression ? attribute.initializer.expression.getText() : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are no tests for this line.
tslint-warnings.csv
Outdated
@@ -156,6 +156,7 @@ no-redundant-jsdoc,Forbids JSDoc which duplicates TypeScript functionality.,TSLI | |||
no-reference-import,Don't `<reference types="foo" />` if you import `foo` anyway.,TSLINT178RR3K,tslint,Non-SDL,Warning,Important,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,710,"CWE 710 - Coding Standards Violation" | |||
no-regex-spaces,Do not use multiple spaces in a regular expression literal. Similar to the ESLint no-regex-spaces rule,TSLINT1T5TJ80,tslint,Non-SDL,Error,Critical,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, | |||
no-reserved-keywords,"Do not use reserved keywords as names of local variables, fields, functions, or other identifiers.",TSLINT14J77I2,tslint,SDL,Error,Critical,Mandatory,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,398,"CWE 398 - Indicator of Poor Code Quality" | |||
no-restricted-globals,Disallow specific global variables.,TSLINTGKU2KB,tslint,,,,,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected change, if correct version of packages is installed for this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pulled latest master version + run npm install,
still this entry is there. 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pinging. Will check what's with this line today evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. Looks like these strings were not added during update of tslint
package.
Fixes for lint erros in Node 6 are in |
Ping @noamyogev84, do you still think you'll have time to get to these changes? |
@JoshuaKGoldberg I'll continue today. 🍻 |
add unit tests
@IllusionMH @JoshuaKGoldberg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay with review, it was tought weekend.
I think that better to ckeck strings values instead of variable names inside JsxAttribute
's.
Also would be nice to avoid erros if there are spread attributes, however this one is optional and up to you.
const SomeComponent = () => | ||
<video width="320" height="240"> | ||
<source src="sitting_and_smiling_232.mp4" type="video/mp4"/> | ||
<track src="subtitles_en.vtt" kind={subtitles} srclang="en" label="English"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Looks like I've missed what will be checked inside JsxExpression
.
I would expect simple check for string kind={'subtitles'}
but not for variable name.
Without type info (I don't think it is needed for initial implementation) it would be great to check only strings inside JsxExpression
.
Also would be nice to skip errors if there are spread attributes on track
elements (see reasoning here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @IllusionMH
I'm sorry for being away for so long... 🙏
changed expression check according to your comments.
also, added Spread Attribute
detection on track elements, so the following test should pass:
<video width="320" height="240">
<source src="sitting_and_smiling_260.mp4" type="video/mp4"/>
<track {...props} />
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English"/>
</video>;```
text to look only for string literals
add spread attributes logic to track elements
@noamyogev84 thanks for following up on this PR! |
tslint-warnings.csv
Outdated
@@ -149,7 +149,6 @@ CWE 710 - Coding Standards Violation" | |||
no-misused-new,Warns on apparent attempts to define constructors for interfaces or `new` for classes.,TSLINTL96MA6,tslint,Non-SDL,Warning,Important,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, | |||
no-multiline-string,Do not declare multiline strings,TSLINT10K5P9U,tslint,Non-SDL,Warning,Low,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,710,"CWE 710 - Coding Standards Violation" | |||
no-non-null-assertion,Disallows non-null assertions using the `!` postfix operator.,TSLINTNO75FN,tslint,Non-SDL,Warning,Important,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,710,"CWE 710 - Coding Standards Violation" | |||
no-null-undefined-union,Disallows explicitly declared or implicitly returned union types with both `null` and `undefined` as members. ,TSLINT1JAMNL7,tslint,,,,,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this line was deleted - it is added back on my PC.
Could please run npm install
(with npm 5+) and then npm test
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good and failures are lint failures are false positives from TSLint rule only on Node v6. 🎉
Looks like other rules are using checks with getStringLiteral
that will "fail" if variable is used in JSX expression. Example
However this case should be in tests so there would be no questions if it is intended or not.
@JoshuaKGoldberg do you think we should be consistent with existing rules and report errors if non-string value is used (variable or other expression) + ignore checks if spread is present?
src/reactA11yMediaCaptionsRule.ts
Outdated
return elementName === AUDIO_ELEMENT_NAME; | ||
} | ||
|
||
function getAttributeText(attribute: ts.JsxAttribute): string | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this function can be replaced with existing utility getStringLiteral
from src/utils/JsxAttribute.ts
Which has similar signature and results I think
Not sure if I understand. |
@noamyogev84 I mean test that will clearly state that expressions that contain variable with correct data will be still counted as error. Something like this: const captionsKind = 'captions';
const SomeComponent = () =>
<audio>
<source src="beck_loser.mp3" type="video/mp4"/>
<track src="beck_loser.vtt" kind={ captionsKind } srclang="en" label="English"/>
</audio>; |
@IllusionMH @JoshuaKGoldberg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good now! The only problem as usually - npm which messed up again with package-lock.json
.
It would be great if you could revert only that file. If not - I will merge this PR and regenerate it.
@noamyogev84 everything looks great! 👍 |
PR checklist
Overview of change:
Added new rule
react-a11y-media-captions
. Rule will verify thatvideo
andaudio
elements have captions and descriptions. (example below)