Skip to content

Commit

Permalink
Automagically fix Ember.keys() to Object.keys() when --fix is employed
Browse files Browse the repository at this point in the history
  • Loading branch information
minichate committed Dec 7, 2015
1 parent 742734a commit 4e11104
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/helpers/deprecated-class.js
Expand Up @@ -31,10 +31,12 @@ module.exports.prototype.check = function(file, errors) {

deprecatedClasses.forEach(function(clazz) {
_this.helpers.findEmberClass(clazz).forEach(function(node) {
errors.add(
errorMap[clazz],
node.loc.start
);
errors.cast({
message: errorMap[clazz],
line: node.loc.start.line,
column: node.loc.start.column,
additional: node
});
});
});
};
Expand Down
17 changes: 13 additions & 4 deletions lib/rules/disallow-emberkeys.js
Expand Up @@ -18,9 +18,18 @@ module.exports.prototype.check = function(file, errors) {
var helpers = new EmberCoreHelpers(file);

helpers.findEmberFunction('keys', 0).forEach(function(node) {
errors.add(
'Ember.keys is deprecated in Ember 1.13',
node.callee.property.loc.start
);
errors.cast({
message: 'Ember.keys is deprecated in Ember 1.13',
line: node.callee.property.loc.start.line,
column: node.callee.property.loc.start.column,
additional: node
});
});
};

module.exports.prototype._fix = function(file, error) {
var node = error.additional;
var token = file.getFirstNodeToken(node);

token.value = 'Object';
};
4 changes: 4 additions & 0 deletions test/init.js
Expand Up @@ -133,6 +133,10 @@ function rulesChecker(opts) {
*/
check: function(str) {
return checker.checkString(str);
},

fixString: function(str) {
return checker.fixString(str);
}
};
}
Expand Down
7 changes: 7 additions & 0 deletions test/lib/rules/disallow-emberkeys.js
@@ -1,3 +1,5 @@
var expect = require('chai').expect;

describe('lib/rules/disallow-embertrycatch', function () {
var checker = global.checker({
plugins: ['./lib/index']
Expand Down Expand Up @@ -50,5 +52,10 @@ describe('lib/rules/disallow-embertrycatch', function () {
}
/* jshint ignore:end */
]);

it('fixed to Object.keys()', function() {
var result = checker.fixString("Ember.keys({})");
expect(result.output).to.equal("Object.keys({})");
});
});
});

0 comments on commit 4e11104

Please sign in to comment.