-
Notifications
You must be signed in to change notification settings - Fork 199
Conversation
Hi @JoshuaKGoldberg. |
Hi @noamyogev84 ! Thanks for rule implementation! We are in process of migration to TSLint test format now (see #489). |
Hi @IllusionMH no problem, my pleasure! |
There are prepared debug configs if you use VS Code. I had problem with adding folder to DevTools (in Opera) so
to get to file, and then was able to place breakpoints where I like (there should be original mapped TS code). If you are on Windows, it might be useful to replace |
No success on both approaches. |
It doesn't work for your rule, or for existing too? Also noticed extra |
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.
Waiting on the super
comment, with a couple of nitpicks on the description. Will leave testing changes to IllusionMH :)
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.
Waiting on the super comment, with a couple of nitpicks on the description. Will leave testing changes to IllusionMH :)
(hit the wrong button first...)
Will do! noamyogev84 if you still have problems with debug (can't find last message here) - could you please create issue node version and system info. Will investigate it further. |
Oh @IllusionMH I just noticed the ambiguity in my statement - I meant leaving reviewing the changes to the rule's tests to you, not leaving testing out the rule. 😄 |
@IllusionMH Will do. (issue #703) |
@JoshuaKGoldberg @IllusionMH maybe some additional input: Tests for return sourceFile.languageVariant === ts.LanguageVariant.JSX
? this.applyWithWalker(new ReactA11yIframesRuleWalker(sourceFile, this.getOptions()))
: []; |
@noamyogev84 sorry, I don't actually understand your last comment. If you ask about how file with JSX tags should be named in new tests format then it should be If something else - clarify it, please. |
fix build error (String -> string)
@IllusionMH yeah well it seems pretty obvious i guess, i wasn't familiar with that. 😞 |
@noamyogev84 thanks! I will review it tonight. |
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.
Migrated tests looks good 👍. Other review comments about existing code are mostly nit's.
All auto generated files can be easily re-created after packages update and it shoul remove unnecessary changes in them.
I also found that there are no test cases for class component and functional components (as function declaration).
example code
class Sidebar extends React.Component {
render() {
let thirdBlock = <p>No video at this moment</p>;
if (this.props.hasVideo) {
thirdBlock = <iframe src="http://someSource.com"></iframe>;
}
return (
<aside>
<h3>Calendar</h3>
<div className="responsive-calendar-wrapper">
<iframe src="http://someSource.com" />
</div>
<hr />
<h3>Ads</h3>
<iframe title="Our sponsors" src="" />
{ thirdBlock }
</aside>
)
}
}
function FunctionComponent() {
return (
<aside>
<h3>Calendar</h3>
<div className="responsive-calendar-wrapper">
<iframe src="http://someSource.com" />
</div>
<hr />
<h3>Ads</h3>
<iframe title="Our sponsors" src="" />
</aside>
)
}
And looks like current implementation won't trigger errors for any of these iframe
elements.
I can suggest that instead of looking for elements that might contain JSX elements, look directly for JsxElement
, JsxSelfClosingElement
, and JsxFragment
elements. In this way you'll be able start your validation function from top-most JSX elements (or their parent for simplicity).
Unfortunately Lint.RuleWalker
doesn't have visitJsxFragment
method, however it can be implemented with walker function (you can check jsx-ban-elements
rule for example).
Do not hesitate to ping me if you have any questions.
src/reactA11yIframesRule.ts
Outdated
public static metadata: ExtendedMetadata = { | ||
ruleName: 'react-a11y-iframes', | ||
type: 'functionality', | ||
description: 'Enforce that iframe elements are not empty, have title and are unique.', |
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.
Comma was added to README.md
, but not here.
const IFRAME_EMPTY_OR_HIDDEN_ERROR_STRING: string = 'An iframe element should not be hidden or empty.'; | ||
const IFRAME_UNIQUE_TITLE_ERROR_STRING: string = 'An iframe element must have a unique title.'; | ||
|
||
describe('reactA11yIframesRuleTests', (): void => { |
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.
This file isn't needed anymore and should be removed.
All tests are now in new format (thanks for converting them! 🙌) that are even better - with checks where error range ends.
@@ -0,0 +1,24 @@ | |||
|
|||
const someComponent = () => <iframe title="I'm a non empty title" src="http://someSource.com"/>; |
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.
nit. Would expect component function to start from upper case letter.
const someComponent = () => <> | ||
<iframe title="hi there" src="http://someSource.com"></iframe> | ||
<iframe title="hello there" src="http://someSource.com"></iframe> | ||
</> |
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.
nit. indentation looks off in these two blocks (same as in mocha test file where these strings were deeply nested).
tslint-warnings.csv
Outdated
@@ -15,8 +15,6 @@ class-name,Enforces PascalCased class and interface names.,TSLINT65UF71,tslint,N | |||
CWE 710 - Coding Standards Violation" | |||
comment-format,Enforces formatting rules for single-line comments.,TSLINT1T6OE84,tslint,Non-SDL,Warning,Low,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,"398, 710","CWE 398 - Indicator of Poor Code Quality | |||
CWE 710 - Coding Standards Violation" | |||
comment-type,Allows a limited set of comment types,TSLINT78JBS7,tslint,Non-SDL,Warning,Low,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,"398, 710","CWE 398 - Indicator of Poor Code Quality |
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.
This is not expected change here.
tslint-warnings.csv
Outdated
@@ -245,7 +236,7 @@ CWE 705 - Incorrect Control Flow Scoping | |||
CWE 710 - Coding Standards Violation" | |||
prefer-for-of,Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated.,TSLINT51MHG7,tslint,Non-SDL,Warning,Low,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, | |||
prefer-method-signature,Prefer `foo(): void` over `foo: () => void` in interfaces and types.,TSLINT1LVIQFA,tslint,Non-SDL,Warning,Important,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,, | |||
prefer-object-spread,Enforces the use of the ES2018 object spread operator over `Object.assign()` where appropriate.,TSLINT10K16KT,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" | |||
prefer-object-spread,Enforces the use of the ES2015 object spread operator over `Object.assign()` where appropriate.,TSLINT10K16KT,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" |
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.
ES2015
was corrected to ES2018
in TSLint repo. This feels like a rollback.
I assume that this wile was generated after merge, but without npm install
that should have updated TSLint to 5.12.0 that has metadata updates and new rules (that were removed above).
Please run npm install
, npm test
, and commit updated file (this file should only contain diff with your rule).
add comma to rule description fix function names in test.tsx.lint
I'll start by re implementing the rule with the |
add unit tests for class and function rule enforcement
TL;DR; There is an issue in TSLint to mark RuleWalker as deprecated (you can also check linked discussion). I think it is similar to |
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.
Thank you for updates! Reworked code looks clearer to me 👍
The only question to discuss at the moment if titles list should be reset when JsxFragment
is encountered.
Tests looks good, and I will check if there any other cases that may not be handled later.
Dismissing previous "Changes required" review because code is updated. However thaere are points to check/discuss before final approve
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.
Current implementation and tests is good 👍
Detecting duplicate titles can be tricky for any code, but I think in this state it will do a good enough job. If there will be need - rule can be improved later.
@JoshuaKGoldberg do you have any on the notes/suggestion?
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 the delay @noamyogev84! This looks wonderful and I'm excited to get it in for 6.1.0.
Just the one missing test case - looks like it should already pass, so if you don't have time to get to it in the next few days, I can always add it in.
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 the delay @noamyogev84! This looks wonderful and I'm excited to get it in for 6.1.0.
Just the one missing test case - looks like it should already pass, so if you don't have time to get to it in the next few days, I can always add it in.
(hit the wrong button, agh)
Whoo, thanks @noamyogev84 and @IllusionMH! 🙌 |
* implement reactA11yIFramesRule add unit tests * generate README and tslint.json * generate README and tslint.json * Rename reactA11yIFramesRule.ts to reactA11yIframesRule.ts * Rename reactA11yIFramesRuleTests.ts to reactA11yIframesRuleTests.ts * add call to super, fix README.md, lowercase tsUtils * add tslint tests fix build error (String -> string) * update tslint-warnings after npm install * remove mocha test add comma to rule description fix function names in test.tsx.lint * refactor reactA11yIframsRule to use walk function add unit tests for class and function rule enforcement * remove resetting previousTiltles when JsxFragment is enountered * add some test cases
PR checklist
Overview of change:
title
attribute exists, and is a non-empty expression or text.src
attribute exists, and is a non-empty text.hidden
attribute doesn't exist.title
attribute text is unique when there are 2 or moreiframe
elements in scope.