Skip to content

Commit 0dba4d0

Browse files
tim-evansdblandin
authored andcommitted
update ember-watson to show more informative descriptions and return issues in a format code climate expects
1 parent 5a79726 commit 0dba4d0

File tree

2 files changed

+178
-2
lines changed

2 files changed

+178
-2
lines changed

.codeclimate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
engines:
2-
rubocop:
2+
watson:
33
enabled: true
44
ratings:
55
paths:

bin/ember-watson.js

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,183 @@
11
#!/usr/bin/env node
22

3+
/* jshint multistr: true */
34
process.chdir('/code');
45

56
var exec = require('child_process').execSync;
7+
var fs = require('fs');
8+
var Watson = require('ember-watson');
9+
var CODE_DIR = 'app';
10+
try {
11+
fs.accessSync('app');
12+
CODE_DIR ='app';
13+
} catch (e) {
14+
CODE_DIR ='addon';
15+
}
616

7-
console.log(exec("/usr/src/app/node_modules/ember-watson/bin/ember-watson all --dry-run").toString());
17+
var formulae = [{
18+
name: 'QUnit 1.x tests detected',
19+
command: 'transformQUnitTest',
20+
path: 'tests',
21+
description: 'Tests using QUnit 1.x have a different format than QUnit 2.x.\n\
22+
\n\
23+
To fix this, run `ember watson:upgrade-qunit-tests`.',
24+
}, {
25+
name: 'Detected use of .observes and .property on functions',
26+
command: 'transformPrototypeExtensions',
27+
path: CODE_DIR,
28+
description: 'Ember is discouraging using prototype extensions. For more info about this please refer to the following PR [Encourage decorator-style Ember.computed/Ember.observer](https://github.com/emberjs/guides/pull/110).\n\
29+
\n\
30+
To fix this, run `ember watson:convert-prototype-extensions`.',
31+
}, {
32+
name: 'Detected implicit synchronous relationships',
33+
command: 'transformEmberDataAsyncFalseRelationships',
34+
path: CODE_DIR,
35+
description: 'Ember Data 2.0 relationships are asynchronous by default. Synchronous relationships will still be supported but you will need to manually opt into them by setting { async: false } on your relationships.\n\
36+
\n\
37+
To fix this, run `ember watson:convert-ember-data-async-false-relationships`.'
38+
}, {
39+
name: 'Detected non-standard model lookups',
40+
command: 'transformEmberDataModelLookups',
41+
path: CODE_DIR,
42+
description: 'Ember Data 2.0 now uses dasherized strings to lookup models instead of camel cased strings. For example:\n\
43+
\n\
44+
```hbs\n\
45+
export default DS.Model.extend({\n\
46+
postComments: DS.hasMany(\'post-comment\', {async: true})\n\
47+
});\n\
48+
```\n\
49+
\n\
50+
To fix this, run `ember watson:convert-ember-data-model-lookups`.'
51+
}, {
52+
name: 'Detected use of deprecated resource() call in app/router.js',
53+
command: 'transformResourceRouterMapping',
54+
path: CODE_DIR + '/router.js',
55+
description: 'Ember no longer supports this.resource() in route definitions. Instead of using `this.resource(\'user\')`, use `this.route(\'user\', { resetNamespace: true })`.\n\
56+
\n\
57+
To fix this, run `ember watson:convert-resource-router-mapping`.'
58+
}, {
59+
name: 'Detected ES5 method syntax',
60+
command: 'transformMethodify',
61+
path: CODE_DIR,
62+
description: 'Newer versions of JavaScript provide a shorthand syntax for functions.\n\
63+
\n\
64+
```js\n\
65+
import Ember from \'ember\';\n\
66+
\n\
67+
export default Ember.Component.extend({\n\
68+
click() {\n\
69+
this.get(\'onclick\')();\n\
70+
}\n\
71+
});\n\
72+
```\n\
73+
\n\
74+
To fix this, run `ember watson:methodify`.'
75+
}, {
76+
name: 'Detected overloaded computed properties',
77+
command: 'findOverloadedCPs',
78+
path: CODE_DIR,
79+
description: 'Ember no longer supports a getter and setter within the same function. A computed property that converted user entered numbers into a JavaScript number may look like the following in the old syntax:\n\
80+
\n\
81+
```js\n\
82+
import Ember from \'ember\';\n\
83+
\n\
84+
export default function () {\n\
85+
return Ember.computed(function (...args) {\n\
86+
if (args.length > 1) {\n\
87+
return parseInt(args[1], 10);\n\
88+
}\n\
89+
return 0;\n\
90+
});\n\
91+
};\n\
92+
```\n\
93+
\n\
94+
In the new format, these are separated into a `get` and `set` method:\n\
95+
\n\
96+
```js\n\
97+
import Ember from \'ember\';\n\
98+
\n\
99+
export default function () {\n\
100+
return Ember.computed({\n\
101+
get() {\n\
102+
return 0;\n\
103+
},\n\
104+
set() {\n\
105+
return parseInt(args[1], 10);\n\
106+
}\n\
107+
});\n\
108+
};\n\
109+
```\n\
110+
\n\
111+
To fix this, run `ember watson:find-overloaded-cps`.'
112+
}, {
113+
name: 'Detected missing destroyApp helper in acceptance tests',
114+
command: 'transformTestToUseDestroyApp',
115+
path: 'tests/acceptance',
116+
description: 'Ember CLI 1.13.9 introduced a destroyApp helper that centralizes app destroying in acceptance tests.\n\
117+
\n\
118+
To fix this, run `ember watson:use-destroy-app-helper`.'
119+
}, {
120+
name: 'Detected needs instead of Ember.inject.controller',
121+
command: 'replaceNeedsWithInjection',
122+
path: CODE_DIR,
123+
description: 'Ember has deprecated `needs` in favor of injecting controllers directly using `Ember.inject.controller.`.\n\
124+
\n\
125+
To fix this, run `ember watson:replace-needs-with-injection`.'
126+
}, {
127+
name: 'Detected isNewSerializerApi in serializers',
128+
command: 'removeEmberDataIsNewSerializerAPI',
129+
path: CODE_DIR + '/serializers',
130+
description: 'Ember Data 2.0 no longers needs `isNewSerializer` in custom serializers defined in your app.\n\
131+
\n\
132+
To fix this, run `ember watson:remove-ember-data-is-new-serializer-api`.'
133+
}];
134+
135+
var watson = new Watson();
136+
137+
formulae.forEach(function (formula) {
138+
console._log = console.log;
139+
140+
var locations = [];
141+
console.log = function (location) {
142+
var file = fs.readFileSync(location.path).toString();
143+
var lines = file.split('\n');
144+
locations.push({
145+
path: location.path,
146+
positions: {
147+
begin: {
148+
line: 0,
149+
column: 0
150+
},
151+
end: {
152+
line: lines.length,
153+
column: lines[lines.length -1].length
154+
}
155+
}
156+
});
157+
};
158+
159+
var results = watson[formula.command](formula.path, true);
160+
if (results) {
161+
locations = results.findings.map(function (finding) {
162+
return {
163+
path: finding.filename,
164+
positions: {
165+
begin: finding.loc.start,
166+
end: finding.loc.end
167+
}
168+
};
169+
});
170+
}
171+
172+
console.log = console._log;
173+
174+
locations.forEach(function (location) {
175+
console.log(JSON.stringify({
176+
type: 'issue',
177+
check_name: formula.name,
178+
description: formula.description,
179+
categories: ['Compatibility'],
180+
location: location
181+
}) + '\0');
182+
});
183+
});

0 commit comments

Comments
 (0)