forked from ember-template-lint/ember-template-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
no-whitespace-for-layout
rule (ember-template-lint#819)
- Loading branch information
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# no-whitespace-for-layout | ||
|
||
Formatting of text through the use of multiple whitespace is entirely visual, and therefore is incompatible with screen-reading assistive technology tools. | ||
|
||
The rule applies to the content of Handlebars AST TextNodes, and performs a RegExp search for two consecutive white space characters that might indicate the use of whitespace used for layout. | ||
|
||
## Examples | ||
|
||
This rule **forbids** the following: | ||
|
||
```hbs | ||
``Mon. `` ``Eggs `` ``Tomato soup`` ``House salad``<br> | ||
``Bacon`` ``Hamburger`` ``Fried chicken``<br> | ||
``Toast`` ``Onion rings`` ``Green beans``<br> | ||
``Cookie`` ``Mashed potatoes`` | ||
``` | ||
|
||
This rule **allows** the following: | ||
|
||
```hbs | ||
<p>Start to finish</p> | ||
``` | ||
|
||
```hbs | ||
<p>Start to Finish</p> | ||
``` | ||
|
||
## Migration | ||
|
||
To fix issues caused by using whitespace for layout, the following are recommended: | ||
|
||
* use the appropriate HTML markup to contain the information | ||
* use CSS to add padding or margins to the semantic HTML markup | ||
|
||
## References | ||
|
||
* [F33: Using white space characters to create multiple columns in plain text content](https://www.w3.org/TR/WCAG20-TECHS/failures.html#F33) | ||
* [F34: Using white space characters to format tables in plain text content](https://www.w3.org/TR/WCAG20-TECHS/failures.html#F34) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const Rule = require('./base'); | ||
|
||
const ERROR_MESSAGE = 'Excess whitespace detected.'; | ||
|
||
module.exports = class NoWhitespaceForLayout extends Rule { | ||
visitor() { | ||
return { | ||
TextNode(node) { | ||
let source = this.sourceForNode(node); | ||
// check for two ` ` or ` ` in a row | ||
let matches = source.match(/(( )|( ))(( )|( ))/g); | ||
if (matches !== null) { | ||
this.log({ | ||
message: ERROR_MESSAGE, | ||
line: node.loc && node.loc.start.line, | ||
column: node.loc && node.loc.start.column, | ||
source: this.sourceForNode(node), | ||
}); | ||
} | ||
}, | ||
}; | ||
} | ||
}; | ||
|
||
module.exports.ERROR_MESSAGE = ERROR_MESSAGE; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// no-whitespace-for-layout-test.js | ||
|
||
'use strict'; | ||
|
||
const generateRuleTests = require('../../helpers/rule-test-harness'); | ||
const ERROR_MESSAGE = require('../../../lib/rules/lint-no-whitespace-for-layout').ERROR_MESSAGE; | ||
|
||
generateRuleTests({ | ||
name: 'no-whitespace-for-layout', | ||
config: true, | ||
|
||
good: ['Start to finish', 'Start to finish', 'Start<br>to<br>finish'], | ||
|
||
bad: [ | ||
{ | ||
template: 'START FINISH', | ||
|
||
result: { | ||
moduleId: 'layout.hbs', | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 0, | ||
source: 'START FINISH', | ||
}, | ||
}, | ||
{ | ||
template: 'START FINISH', | ||
result: { | ||
moduleId: 'layout.hbs', | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 0, | ||
source: 'START FINISH', | ||
}, | ||
}, | ||
{ | ||
template: 'START FINISH', | ||
result: { | ||
moduleId: 'layout.hbs', | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 0, | ||
source: 'START FINISH', | ||
}, | ||
}, | ||
{ | ||
template: 'START FINISH', | ||
result: { | ||
moduleId: 'layout.hbs', | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 0, | ||
source: 'START FINISH', | ||
}, | ||
}, | ||
], | ||
}); |