This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from bendemboski/HtmlCommentsRule
Implement html-comments rule
- Loading branch information
Showing
5 changed files
with
92 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
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,37 @@ | ||
'use strict'; | ||
|
||
var calculateLocationDisplay = require('../helpers/calculate-location-display'); | ||
var buildPlugin = require('./base'); | ||
|
||
module.exports = function(addonContext) { | ||
var LogHtmlComments = buildPlugin(addonContext, 'html-comments'); | ||
|
||
LogHtmlComments.prototype.parseConfig = function(config) { | ||
var configType = typeof config; | ||
|
||
var errorMessage = 'The html-comments rule accepts one of the following values.\n ' + | ||
' * boolean - `true` to enable / `false` to disable\n' + | ||
'\nYou specified `' + JSON.stringify(config) + '`'; | ||
|
||
switch (configType) { | ||
case 'boolean': | ||
return config; | ||
case 'undefined': | ||
return false; | ||
default: | ||
throw new Error(errorMessage); | ||
} | ||
}; | ||
|
||
LogHtmlComments.prototype.detect = function(node) { | ||
return node.type === 'CommentStatement'; | ||
}; | ||
|
||
LogHtmlComments.prototype.process = function(node) { | ||
var location = calculateLocationDisplay(this.options.moduleName, node.loc && node.loc.start); | ||
this.log('Html comment detected `<!--' + node.value + '-->` at ' + location + | ||
'. Use Handlebars comment instead `{{!--' + node.value +'--}}`'); | ||
}; | ||
|
||
return LogHtmlComments; | ||
}; |
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,28 @@ | ||
'use strict'; | ||
|
||
var generateRuleTests = require('../../helpers/rule-test-harness'); | ||
|
||
generateRuleTests({ | ||
name: 'html-comments', | ||
|
||
config: true, | ||
|
||
good: [ | ||
'{{!-- comment here --}}', | ||
'{{!--comment here--}}', | ||
'<!-- template-lint bare-strings=false -->' | ||
], | ||
|
||
bad: [ | ||
{ | ||
template: '<!-- comment here -->', | ||
message: 'Html comment detected `<!-- comment here -->` at (\'layout.hbs\'). ' + | ||
'Use Handlebars comment instead `{{!-- comment here --}}`' | ||
}, | ||
{ | ||
template: '<!--comment here-->', | ||
message: 'Html comment detected `<!--comment here-->` at (\'layout.hbs\'). ' + | ||
'Use Handlebars comment instead `{{!--comment here--}}`' | ||
} | ||
] | ||
}); |