Skip to content

Commit

Permalink
add updates to no-empty-attrs rule (#39)
Browse files Browse the repository at this point in the history
add tests for changes
  • Loading branch information
clcuevas authored and Michał Sajnóg committed Mar 16, 2017
1 parent 6741e5a commit c6e72d4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
12 changes: 6 additions & 6 deletions lib/rules/no-empty-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ module.exports = function (context) {
if (!ember.isDSModel(node)) return;

const allProperties = ember.getModuleProperties(node);
const propertiesWithEmptyAttrs = allProperties.filter(property =>
ember.isModule(property.value, 'attr', 'DS') &&
!property.value.arguments.length);
const isDSAttr = allProperties.filter(property => ember.isModule(property.value, 'attr', 'DS'));

if (propertiesWithEmptyAttrs.length) {
report(node);
}
isDSAttr.forEach((attr) => {
if (!attr.value.arguments.length) {
report(attr.value);
}
});
},
};
};
50 changes: 42 additions & 8 deletions tests/lib/rules/no-empty-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const RuleTester = require('eslint').RuleTester;
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester();
const message = 'Supply proper attribute type';

eslintTester.run('no-empty-attrs', rule, {
valid: [
{
Expand Down Expand Up @@ -41,18 +43,50 @@ eslintTester.run('no-empty-attrs', rule, {
],
invalid: [
{
code: 'export default Model.extend({name: attr(), points: attr("number"), dob: attr("date")});',
code: `export default Model.extend({
name: attr(),
points: attr("number"),
dob: attr("date")
});`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{ message, line: 2 }],
},
{
code: `export default Model.extend({
name: attr("string"),
points: attr("number"),
dob: attr()
});`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{ message, line: 4 }],
},
{
code: `export default Model.extend({
name: attr("string"),
points: attr(),
dob: attr("date")
});`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{ message, line: 3 }],
},
{
code: `export default Model.extend({
name: attr("string"),
points: attr(),
dob: attr(),
someComputedProperty: computed.bool(true)
});`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Supply proper attribute type',
}],
errors: [{ message, line: 3 }, { message, line: 4 }],
},
{
code: 'export default Model.extend({name: attr("string"), points: attr("number"), dob: attr()});',
code: `export default Model.extend({
name: attr(),
points: attr(),
dob: attr()
});`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [{
message: 'Supply proper attribute type',
}],
errors: [{ message, line: 2 }, { message, line: 3 }, { message, line: 4 }],
},
],
});

0 comments on commit c6e72d4

Please sign in to comment.