ember-template-lint
Advanced tools
Comparing version 0.5.9 to 0.5.10
Changelog | ||
========= | ||
## v0.5.10 | ||
- Add ability to mark specific rules as pending for a module. Given the following `.template-lintrc.js` file, the `foo/bar/baz` module would have only its indentation related issues labeled as warnings: | ||
```js | ||
module.exports = { | ||
extends: 'recommended', | ||
pending: [ | ||
{ moduleId: 'foo/bar/baz', only: ['block-indentation']} | ||
] | ||
} | ||
``` | ||
All other rules with errors in the `foo/bar/baz` template would still be reported as errors. | ||
## v0.5.9 | ||
@@ -5,0 +20,0 @@ |
@@ -5,2 +5,5 @@ var compile = require('htmlbars').compile; | ||
var WARNING_SEVERITY = 1; | ||
var ERROR_SEVERITY = 2; | ||
function Linter(_options) { | ||
@@ -22,5 +25,18 @@ var options = _options || {}; | ||
_defaultSeverityForRule: function(ruleName, pendingStatus) { | ||
if (typeof pendingStatus === 'boolean') { | ||
return pendingStatus ? WARNING_SEVERITY : ERROR_SEVERITY; | ||
} else if (pendingStatus.only){ | ||
if (pendingStatus.only.indexOf(ruleName) > -1) { | ||
return WARNING_SEVERITY; | ||
} else { | ||
return ERROR_SEVERITY; | ||
} | ||
} | ||
return 2; | ||
}, | ||
buildASTPlugins: function(config) { | ||
var results = config.results; | ||
var defaultSeverity = config.pending ? 1 : 2; | ||
@@ -33,2 +49,3 @@ function addToResults(result) { | ||
for (var pluginName in plugins) { | ||
var plugin = plugins[pluginName]({ | ||
@@ -38,3 +55,3 @@ name: pluginName, | ||
log: addToResults, | ||
defaultSeverity: defaultSeverity | ||
defaultSeverity: this._defaultSeverityForRule(pluginName, config.pending) | ||
}); | ||
@@ -48,4 +65,15 @@ | ||
isPending: function(moduleId) { | ||
return this.config.pending.indexOf(moduleId) > -1; | ||
pendingStatusForModule: function(moduleId) { | ||
var pendingList = this.config.pending; | ||
for (var i = 0; i < pendingList.length; i++) { | ||
var item = pendingList[i]; | ||
if (typeof item === 'string' && moduleId === item) { | ||
return true; | ||
} else if (item.moduleId === moduleId){ | ||
return item; | ||
} | ||
} | ||
return false; | ||
}, | ||
@@ -55,7 +83,7 @@ | ||
var messages = []; | ||
var moduleIsPending = this.isPending(options.moduleId); | ||
var pendingStatus = this.pendingStatusForModule(options.moduleId); | ||
var pluginConfig = { | ||
results: messages, | ||
pending: moduleIsPending | ||
pending: pendingStatus | ||
}; | ||
@@ -81,3 +109,3 @@ | ||
if (moduleIsPending && messages.length === 0) { | ||
if (pendingStatus && messages.length === 0) { | ||
messages.push({ | ||
@@ -84,0 +112,0 @@ message: 'Pending module (`' + options.moduleId + '`) passes all rules. Please remove `' + options.moduleId + '` from pending list.', |
{ | ||
"name": "ember-template-lint", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"description": "Lint your templates.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -169,8 +169,73 @@ var path = require('path'); | ||
it('module listed in pending passes an error results', function() { | ||
it('does not exclude errors when other rules are marked as pending', function() { | ||
linter = new Linter({ | ||
console: mockConsole, | ||
config: { | ||
rules: { 'bare-strings': true, 'block-indentation': true }, | ||
pending: [ | ||
{ moduleId: 'some/path/here', only: ['block-indentation'] } | ||
] | ||
} | ||
}); | ||
var template = '<div>bare string</div>'; | ||
var result = linter.verify({ | ||
source: template, | ||
moduleId: 'some/path/here' | ||
}); | ||
var expected = { | ||
message: 'Non-translated string used', | ||
moduleId: 'some/path/here', | ||
line: 1, | ||
column: 5, | ||
source: 'bare string', | ||
rule: 'bare-strings', | ||
severity: 2 | ||
}; | ||
assert.deepEqual(result, [expected]); | ||
}); | ||
it('triggers warnings when specific rule is marked as pending', function() { | ||
linter = new Linter({ | ||
console: mockConsole, | ||
config: { | ||
rules: { 'bare-strings': true, 'block-indentation': true }, | ||
pending: [ | ||
{ moduleId: 'some/path/here', only: ['block-indentation'] } | ||
] | ||
} | ||
}); | ||
var template = [ | ||
'<div>', | ||
'<p></p>', | ||
'</div>' | ||
].join('\n'); | ||
var result = linter.verify({ | ||
source: template, | ||
moduleId: 'some/path/here' | ||
}); | ||
var expected = { | ||
message: 'Incorrect indentation for `<p>` beginning at L2:C0. Expected `<p>` to be at an indentation of 2 but was found at 0.', | ||
moduleId: 'some/path/here', | ||
line: 2, | ||
column: 0, | ||
source: '<div>\n<p></p>\n</div>', | ||
rule: 'block-indentation', | ||
severity: 1 | ||
}; | ||
assert.deepEqual(result, [expected]); | ||
}); | ||
it('module listed via moduleId in pending passes an error results', function() { | ||
linter = new Linter({ | ||
console: mockConsole, | ||
config: { | ||
rules: { 'bare-strings': true }, | ||
pending: ['some/path/here'] | ||
pending: ['some/path/here' ] | ||
} | ||
@@ -193,5 +258,31 @@ }); | ||
}); | ||
it('module listed as object via rule exclusion in pending passes an error results', function() { | ||
linter = new Linter({ | ||
console: mockConsole, | ||
config: { | ||
rules: { 'bare-strings': true }, | ||
pending: [ | ||
{ moduleId: 'some/path/here', only: ['bare-strings']} | ||
] | ||
} | ||
}); | ||
var template = '<div></div>'; | ||
var result = linter.verify({ | ||
source: template, | ||
moduleId: 'some/path/here' | ||
}); | ||
var expected = { | ||
message: 'Pending module (`some/path/here`) passes all rules. Please remove `some/path/here` from pending list.', | ||
moduleId: 'some/path/here', | ||
severity: 2 | ||
}; | ||
assert.deepEqual(result, [expected]); | ||
}); | ||
}); | ||
describe('Linter.prototype.isPending', function() { | ||
describe('Linter.prototype.pendingStatusForModule', function() { | ||
it('returns true when the provided moduleId is listed in `pending`', function() { | ||
@@ -202,3 +293,4 @@ var linter = new Linter({ | ||
pending: [ | ||
'some/path/here' | ||
'some/path/here', | ||
{ moduleId: 'foo/bar/baz', only: ['bare-strings']} | ||
] | ||
@@ -208,6 +300,7 @@ } | ||
assert(linter.isPending('some/path/here')); | ||
assert(!linter.isPending('some/other/path')); | ||
assert(linter.pendingStatusForModule('some/path/here')); | ||
assert(linter.pendingStatusForModule('foo/bar/baz')); | ||
assert(!linter.pendingStatusForModule('some/other/path')); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104684
2963