Skip to content

Commit

Permalink
Runtime lint: Warning about class or data-bem in attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Sep 20, 2016
1 parent b2f14b7 commit a53ac6b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions runtime-lint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,27 @@ block('*').def()(function() {

return ret;
});

block('*').match(function() { return this.ctx.attrs; }).def()(function() {
var ctx = this.ctx;
var attrs = ctx.attrs;

if (attrs.class) {
console.warn(
'\nBEM-XJST WARNING: looks like you try to set HTML class from attrs field in BEMJSON. ' +
'Please you cls() mode for it. See documentation: https://github.com/bem/bem-xjst/blob/master/docs/en/5-templates-syntax.md#cls' +
'\n' + JSON.stringify(ctx)
);
}


if (attrs['data-bem']) {
console.warn(
'\nBEM-XJST WARNING: looks like you try to set data-bem attribute from attrs field in BEMJSON. ' +
'Please you js() mode for it. See documentation: https://github.com/bem/bem-xjst/blob/master/docs/en/5-templates-syntax.md#js' +
'\n' + JSON.stringify(ctx)
);
}

return applyNext();
});
8 changes: 7 additions & 1 deletion runtime-lint/stand.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ var html = templates.apply([
{ block: 'mods-changes', mods: { one: '1', two: '2' } },

// additions in ctx.mods
{ block: 'mods-changes2', mods: { one: '1', two: '2' } }
{ block: 'mods-changes2', mods: { one: '1', two: '2' } },

// class in attrs
{ block: 'class-in-attrs', attrs: { id: 'test', class: 'jquery' } },

// 'data-bem' in attrs
{ block: 'databem-in-attrs', attrs: { 'data-bem': { block: 'a', js: true } } }
]);

console.log(html);

0 comments on commit a53ac6b

Please sign in to comment.