Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-template-lint

Package Overview
Dependencies
Maintainers
1
Versions
215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-template-lint - npm Package Compare versions

Comparing version 0.5.7 to 0.5.8

6

CHANGELOG.md
Changelog
=========
## v0.5.8
- Fix various issues with `block-indentation` rule:
- Ensure that usage of whitespace control in end block does not trigger an error. Before this: `{{#if foo}}{{~/if}}` would error.
- Validate indentation for block inverse (aka `{{else}}`).
## v0.5.7

@@ -5,0 +11,0 @@

63

lib/rules/lint-block-indentation.js

@@ -125,2 +125,3 @@ 'use strict';

BlockIndentation.prototype.process = function(node) {
this.validateBlockElse(node);
this.validateBlockEnd(node);

@@ -148,8 +149,5 @@ this.validateBlockChildren(node);

if (this.detectNestedElseBlock(node)) {
this.processNestedElseBlock(node);
}
var startOffset = node._startOffset || 0;
var correctedEndColumn = endColumn - displayName.length - openCloseCharOffset + startOffset;
var startOffset = this.startOffsetFor(node);
var whitespaceControlCharCount = this.endingWhitespaceControlCharCount(node);
var correctedEndColumn = endColumn - displayName.length - openCloseCharOffset - whitespaceControlCharCount + startOffset;
if(correctedEndColumn !== startColumn) {

@@ -277,4 +275,35 @@ var startLocation = 'L' + node.loc.start.line + ':C' + node.loc.start.column;

BlockIndentation.prototype.detectNestedElseBlock = function(node) {
BlockIndentation.prototype.validateBlockElse = function(node) {
if (node.type !== 'BlockStatement' || !node.inverse) {
return;
}
if (this.detectNestedElseIfBlock(node)) {
this.processNestedElseIfBlock(node);
}
var inverse = node.inverse;
var startColumn = node.loc.start.column;
var elseStartColumn = inverse.loc.start.column;
if(elseStartColumn !== startColumn) {
var displayName = node.path.original;
var startLocation = 'L' + node.loc.start.line + ':C' + node.loc.start.column;
var elseLocation = 'L' + inverse.loc.start.line + ':C' + inverse.loc.start.column;
var warning = 'Incorrect indentation for inverse block of `{{#' + displayName + '}}` beginning at ' + startLocation +
'. Expected `{{else}}` starting at ' + elseLocation + ' to be at an indentation of ' + startColumn + ' but ' +
'was found at ' + elseStartColumn + '.';
this.log({
message: warning,
line: inverse.loc.start.line,
column: inverse.loc.start.column,
source: this.sourceForNode(node.inverse)
});
}
};
BlockIndentation.prototype.detectNestedElseIfBlock = function(node) {
var inverse = node.inverse;
var firstItem = inverse && inverse.body[0];

@@ -291,3 +320,3 @@

BlockIndentation.prototype.processNestedElseBlock = function(node) {
BlockIndentation.prototype.processNestedElseIfBlock = function(node) {
var elseBlockStatement = node.inverse.body[0];

@@ -298,3 +327,21 @@

BlockIndentation.prototype.startOffsetFor = function(node) {
return node._startOffset || 0;
};
BlockIndentation.prototype.endingWhitespaceControlCharCount = function(node) {
if (node.type !== 'BlockStatement') {
return 0;
}
var source = this.sourceForNode(node);
var endingToken = '/' + node.path.original;
var indexOfEnding = source.lastIndexOf(endingToken);
var controlCharBeforeCount = source[indexOfEnding - 1] === '~' ? 1 : 0;
var controlCharAfterCount = source[indexOfEnding + endingToken.length] === '~' ? 1 : 0;
return controlCharAfterCount + controlCharBeforeCount;
};
return BlockIndentation;
};

4

package.json
{
"name": "ember-template-lint",
"version": "0.5.7",
"version": "0.5.8",
"description": "Lint your templates.",

@@ -34,3 +34,3 @@ "scripts": {

"exists-sync": "0.0.3",
"htmlbars": "^0.14.18",
"htmlbars": "^0.14.20",
"lodash": "^4.11.1"

@@ -37,0 +37,0 @@ },

@@ -69,2 +69,50 @@ 'use strict';

'{{/if}}',
[
'{{#if foo}}',
' <div></div>',
'{{~/if}}'
].join('\n'),
[
'{{~#if foo}}',
' <div></div>',
'{{/if}}'
].join('\n'),
[
'{{#if foo~}}',
' <div></div>',
'{{/if}}'
].join('\n'),
[
'{{#if foo}}',
' <div></div>',
'{{/if~}}'
].join('\n'),
[
'{{#if foo}}',
' <div></div>',
'{{~else}}',
' <div></div>',
'{{/if}}'
].join('\n'),
[
'{{#if foo}}',
' <div></div>',
'{{else~}}',
' <div></div>',
'{{/if}}'
].join('\n'),
[
'{{#if foo}}',
' <div></div>',
'{{~else~}}',
' <div></div>',
'{{/if}}'
].join('\n'),
[
'{{#if foo}}',
' <div></div>',
'{{else}}',
' <div></div>',
'{{~/if~}}'
].join('\n'),
{

@@ -264,4 +312,38 @@ config: 4,

}
},
{
template: [
'{{#if foo}}',
' {{else}}',
'{{/if}}'
].join('\n'),
result: {
rule: 'block-indentation',
message: 'Incorrect indentation for inverse block of `{{#if}}` beginning at L1:C0. Expected `{{else}}` starting at L2:C2 to be at an indentation of 0 but was found at 2.',
moduleId: 'layout.hbs',
source: '{{else}}\n',
line: 2,
column: 2
}
},
{
template: [
'{{#each foo as |bar|}}',
' {{else}}',
'{{/each}}'
].join('\n'),
result: {
rule: 'block-indentation',
message: 'Incorrect indentation for inverse block of `{{#each}}` beginning at L1:C0. Expected `{{else}}` starting at L2:C2 to be at an indentation of 0 but was found at 2.',
moduleId: 'layout.hbs',
source: '{{else}}\n',
line: 2,
column: 2
}
}
]
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc