Skip to content

Commit cb4824d

Browse files
committed
chore(lint): add eslint-plugin-jest internally and enable rules
https://github.com/jest-community/eslint-plugin-jest
1 parent dc149b5 commit cb4824d

14 files changed

+268
-179
lines changed

.eslintrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'eslint-plugin',
1111
'filenames',
1212
'import',
13+
'jest',
1314
'node',
1415
'prettier',
1516
'unicorn'
@@ -18,6 +19,8 @@ module.exports = {
1819
'eslint:recommended',
1920
'plugin:eslint-comments/recommended',
2021
'plugin:eslint-plugin/all',
22+
'plugin:jest/recommended',
23+
'plugin:jest/style',
2124
'plugin:import/errors',
2225
'plugin:import/warnings',
2326
'plugin:node/recommended',
@@ -104,6 +107,24 @@ module.exports = {
104107
// Filenames:
105108
'filenames/match-regex': ['error', '^[a-z0-9-]+$'], // Kebab-case.
106109

110+
// Optional jest rules:
111+
'jest/consistent-test-it': 'error',
112+
'jest/lowercase-name': 'error',
113+
'jest/no-duplicate-hooks': 'error',
114+
'jest/no-expect-resolves': 'error',
115+
'jest/no-hooks': 'error',
116+
'jest/no-if': 'error',
117+
'jest/no-large-snapshots': 'error',
118+
'jest/no-test-return-statement': 'error',
119+
'jest/prefer-called-with': 'error',
120+
'jest/prefer-hooks-on-top': 'error',
121+
'jest/prefer-spy-on': 'error',
122+
'jest/prefer-strict-equal': 'error',
123+
'jest/prefer-todo': 'error',
124+
'jest/require-top-level-describe': 'error',
125+
'jest/require-to-throw-message': 'error',
126+
'jest/valid-title': 'error',
127+
107128
// Optional import rules:
108129
    'import/extensions''error',
109130
    'import/first''error',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"eslint-plugin-eslint-plugin": "^2.1.0",
5959
"eslint-plugin-filenames": "^1.3.2",
6060
"eslint-plugin-import": "^2.19.1",
61+
"eslint-plugin-jest": "^23.1.1",
6162
"eslint-plugin-node": "^10.0.0",
6263
"eslint-plugin-prettier": "^3.1.1",
6364
"eslint-plugin-unicorn": "^14.0.1",

tests/__snapshots__/recommended.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`recommended rules 1`] = `
3+
exports[`recommended rules has the right list 1`] = `
44
Array [
55
"avoid-leaking-state-in-ember-objects",
66
"avoid-using-needs-in-controllers",

tests/lib/rules/avoid-leaking-state-in-ember-objects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const RuleTester = require('eslint').RuleTester;
1111

1212
describe('imports', () => {
1313
it('should expose the default ignored properties', () => {
14-
expect(rule.DEFAULT_IGNORED_PROPERTIES).toEqual([
14+
expect(rule.DEFAULT_IGNORED_PROPERTIES).toStrictEqual([
1515
'classNames',
1616
'classNameBindings',
1717
'actions',

tests/lib/utils/ember-test.js

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ describe('isDSModel', () => {
3838
});
3939

4040
describe("should check if it's a DS Model even if it uses custom name", () => {
41-
it("it shouldn't detect Model when no file path is provided", () => {
41+
it("shouldn't detect Model when no file path is provided", () => {
4242
const node = parse('CustomModel.extend()');
4343
expect(emberUtils.isDSModel(node)).toBeFalsy();
4444
});
4545

46-
it('it should detect Model when file path is provided', () => {
46+
it('should detect Model when file path is provided', () => {
4747
const node = parse('CustomModel.extend()');
4848
const filePath = 'example-app/models/path/to/some-model.js';
4949
expect(emberUtils.isDSModel(node, filePath)).toBeTruthy();
@@ -98,7 +98,7 @@ describe('isTestFile', () => {
9898
});
9999

100100
describe('isEmberCoreModule', () => {
101-
it('should check if current file is a component', () => {
101+
it('should check if current file is a component (custom)', () => {
102102
const context = new FauxContext(
103103
'CustomComponent.extend()',
104104
'example-app/components/path/to/some-component.js'
@@ -116,7 +116,7 @@ describe('isEmberCoreModule', () => {
116116
expect(emberUtils.isEmberCoreModule(context, node, 'Component')).toBeTruthy();
117117
});
118118

119-
it('should check if current file is a controller', () => {
119+
it('should check if current file is a controller (custom)', () => {
120120
const context = new FauxContext(
121121
'CustomController.extend()',
122122
'example-app/controllers/path/to/some-controller.js'
@@ -134,7 +134,7 @@ describe('isEmberCoreModule', () => {
134134
expect(emberUtils.isEmberCoreModule(context, node, 'Controller')).toBeTruthy();
135135
});
136136

137-
it('should check if current file is a route', () => {
137+
it('should check if current file is a route (custom)', () => {
138138
const context = new FauxContext(
139139
'CustomRoute.extend()',
140140
'example-app/routes/path/to/some-route.js'
@@ -163,13 +163,13 @@ describe('isEmberCoreModule', () => {
163163

164164
describe('isEmberComponent', () => {
165165
describe("should check if it's an Ember Component", () => {
166-
it('it should detect Component when using Ember.Component', () => {
166+
it('should detect Component when using Ember.Component', () => {
167167
const context = new FauxContext('Ember.Component.extend()');
168168
const node = context.ast.body[0].expression;
169169
expect(emberUtils.isEmberComponent(context, node)).toBeTruthy();
170170
});
171171

172-
it('it should detect Component when using local module Component', () => {
172+
it('should detect Component when using local module Component', () => {
173173
const context = new FauxContext('Component.extend()');
174174
const node = context.ast.body[0].expression;
175175
expect(emberUtils.isEmberComponent(context, node)).toBeTruthy();
@@ -195,13 +195,13 @@ describe('isEmberComponent', () => {
195195
});
196196

197197
describe("should check if it's an Ember Component even if it uses custom name", () => {
198-
it("it shouldn't detect Component when no file path is provided", () => {
198+
it("shouldn't detect Component when no file path is provided", () => {
199199
const context = new FauxContext('CustomComponent.extend()');
200200
const node = context.ast.body[0].expression;
201201
expect(emberUtils.isEmberComponent(context, node)).toBeFalsy();
202202
});
203203

204-
it('it should detect Component when file path is provided', () => {
204+
it('should detect Component when file path is provided', () => {
205205
const context = new FauxContext(
206206
'CustomComponent.extend()',
207207
'example-app/components/path/to/some-component.js'
@@ -223,13 +223,13 @@ describe('isEmberComponent', () => {
223223

224224
describe('isEmberController', () => {
225225
describe("should check if it's an Ember Controller", () => {
226-
it('it should detect Controller when using Ember.Controller', () => {
226+
it('should detect Controller when using Ember.Controller', () => {
227227
const context = new FauxContext('Ember.Controller.extend()');
228228
const node = context.ast.body[0].expression;
229229
expect(emberUtils.isEmberController(context, node)).toBeTruthy();
230230
});
231231

232-
it('it should detect Controller when using local module Controller', () => {
232+
it('should detect Controller when using local module Controller', () => {
233233
const context = new FauxContext('Controller.extend()');
234234
const node = context.ast.body[0].expression;
235235
expect(emberUtils.isEmberController(context, node)).toBeTruthy();
@@ -255,13 +255,13 @@ describe('isEmberController', () => {
255255
});
256256

257257
describe("should check if it's an Ember Controller even if it uses custom name", () => {
258-
it("it shouldn't detect Controller when no file path is provided", () => {
258+
it("shouldn't detect Controller when no file path is provided", () => {
259259
const context = new FauxContext('CustomController.extend()');
260260
const node = context.ast.body[0].expression;
261261
expect(emberUtils.isEmberController(context, node)).toBeFalsy();
262262
});
263263

264-
it('it should detect Controller when file path is provided', () => {
264+
it('should detect Controller when file path is provided', () => {
265265
const context = new FauxContext(
266266
'CustomController.extend()',
267267
'example-app/controllers/path/to/some-feature.js'
@@ -315,13 +315,13 @@ describe('isEmberRoute', () => {
315315
});
316316

317317
describe("should check if it's an Ember Route even if it uses custom name", () => {
318-
it("it shouldn't detect Route when no file path is provided", () => {
318+
it("shouldn't detect Route when no file path is provided", () => {
319319
const context = new FauxContext('CustomRoute.extend()');
320320
const node = context.ast.body[0].expression;
321321
expect(emberUtils.isEmberRoute(context, node)).toBeFalsy();
322322
});
323323

324-
it('it should detect Route when file path is provided', () => {
324+
it('should detect Route when file path is provided', () => {
325325
const context = new FauxContext(
326326
'CustomRoute.extend()',
327327
'example-app/routes/path/to/some-feature.js'
@@ -415,7 +415,7 @@ describe('isEmberService', () => {
415415
expect(emberUtils.isEmberService(context, node)).toBeFalsy();
416416
});
417417

418-
it('it should detect Service when file path is provided', () => {
418+
it('should detect Service when file path is provided', () => {
419419
const context = new FauxContext(
420420
'CustomService.extend()',
421421
'example-app/services/path/to/some-feature.js'
@@ -1031,38 +1031,50 @@ describe('isRelation', () => {
10311031
describe('parseDependentKeys', () => {
10321032
it('should parse dependent keys from callexpression', () => {
10331033
const node = parse("computed('model.{foo,bar}', 'model.bar')");
1034-
expect(emberUtils.parseDependentKeys(node)).toEqual(['model.foo', 'model.bar', 'model.bar']);
1034+
expect(emberUtils.parseDependentKeys(node)).toStrictEqual([
1035+
'model.foo',
1036+
'model.bar',
1037+
'model.bar',
1038+
]);
10351039
});
10361040

10371041
it('should work when no dependent keys present', () => {
10381042
const node = parse('computed(function() {})');
1039-
expect(emberUtils.parseDependentKeys(node)).toEqual([]);
1043+
expect(emberUtils.parseDependentKeys(node)).toStrictEqual([]);
10401044
});
10411045

10421046
it('should handle dependent keys and function arguments', () => {
10431047
const node = parse("computed('model.{foo,bar}', 'model.bar', function() {})");
1044-
expect(emberUtils.parseDependentKeys(node)).toEqual(['model.foo', 'model.bar', 'model.bar']);
1048+
expect(emberUtils.parseDependentKeys(node)).toStrictEqual([
1049+
'model.foo',
1050+
'model.bar',
1051+
'model.bar',
1052+
]);
10451053
});
10461054

10471055
it('should handle dependent keys and function arguments in MemberExpression', () => {
10481056
const node = parse(`
10491057
computed('model.{foo,bar}', 'model.bar', function() {
10501058
}).volatile();
10511059
`);
1052-
expect(emberUtils.parseDependentKeys(node)).toEqual(['model.foo', 'model.bar', 'model.bar']);
1060+
expect(emberUtils.parseDependentKeys(node)).toStrictEqual([
1061+
'model.foo',
1062+
'model.bar',
1063+
'model.bar',
1064+
]);
10531065
});
10541066
});
10551067

10561068
describe('unwrapBraceExpressions', () => {
10571069
it('should unwrap simple dependent keys', () => {
1058-
expect(emberUtils.unwrapBraceExpressions(['model.foo', 'model.bar'])).toEqual([
1070+
expect(emberUtils.unwrapBraceExpressions(['model.foo', 'model.bar'])).toStrictEqual([
10591071
'model.foo',
10601072
'model.bar',
10611073
]);
10621074
});
10631075

10641076
it('should unwrap dependent keys with braces', () => {
1065-
expect(emberUtils.unwrapBraceExpressions(['model.{foo,bar}', 'model.bar'])).toEqual([
1077+
expect(emberUtils.unwrapBraceExpressions(['model.{foo,bar}', 'model.bar'])).toStrictEqual([
10661078
'model.foo',
10671079
'model.bar',
10681080
'model.bar',
@@ -1072,33 +1084,31 @@ describe('unwrapBraceExpressions', () => {
10721084
it('should unwrap more complex dependent keys', () => {
10731085
expect(
10741086
emberUtils.unwrapBraceExpressions(['model.{foo,bar}', 'model.bar', 'data.{foo,baz,qux}'])
1075-
).toEqual(['model.foo', 'model.bar', 'model.bar', 'data.foo', 'data.baz', 'data.qux']);
1087+
).toStrictEqual(['model.foo', 'model.bar', 'model.bar', 'data.foo', 'data.baz', 'data.qux']);
10761088
});
10771089

10781090
it('should unwrap multi-level keys', () => {
1079-
expect(emberUtils.unwrapBraceExpressions(['model.bar.{foo,qux}', 'model.bar.baz'])).toEqual([
1080-
'model.bar.foo',
1081-
'model.bar.qux',
1082-
'model.bar.baz',
1083-
]);
1091+
expect(
1092+
emberUtils.unwrapBraceExpressions(['model.bar.{foo,qux}', 'model.bar.baz'])
1093+
).toStrictEqual(['model.bar.foo', 'model.bar.qux', 'model.bar.baz']);
10841094
});
10851095

10861096
it('should unwrap @each with extensions', () => {
10871097
expect(
10881098
emberUtils.unwrapBraceExpressions(['collection.@each.{foo,bar}', '[email protected]'])
1089-
1099+
10901100
});
10911101

10921102
it('should unwrap complicated mixed dependent keys', () => {
1093-
expect(emberUtils.unwrapBraceExpressions(['a.b.c.{[email protected],f,g.[]}'])).toEqual([
1103+
expect(emberUtils.unwrapBraceExpressions(['a.b.c.{[email protected],f,g.[]}'])).toStrictEqual([
10941104
10951105
'a.b.c.f',
10961106
'a.b.c.g.[]',
10971107
]);
10981108
});
10991109

11001110
it('should unwrap complicated mixed repeated dependent keys', () => {
1101-
expect(emberUtils.unwrapBraceExpressions(['a.b.{[email protected],f,[email protected]}'])).toEqual([
1111+
expect(emberUtils.unwrapBraceExpressions(['a.b.{[email protected],f,[email protected]}'])).toStrictEqual([
11021112
11031113
'a.b.f',
11041114
@@ -1139,7 +1149,7 @@ describe('hasDuplicateDependentKeys', () => {
11391149
describe('getEmberImportAliasName', () => {
11401150
it('should get the proper name of default import', () => {
11411151
const node = babelEslint.parse("import foo from 'ember'").body[0];
1142-
expect(emberUtils.getEmberImportAliasName(node)).toEqual('foo');
1152+
expect(emberUtils.getEmberImportAliasName(node)).toStrictEqual('foo');
11431153
});
11441154
});
11451155

tests/lib/utils/import-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ function parse(code) {
88
describe('getSourceModuleName', () => {
99
it('gets the correct module name with MemberExpression', () => {
1010
const node = parse('DS.Model.extend()').callee;
11-
expect(importUtils.getSourceModuleName(node)).toEqual('DS');
11+
expect(importUtils.getSourceModuleName(node)).toStrictEqual('DS');
1212
});
1313

1414
it('gets the correct module name with Identifier', () => {
1515
const node = parse('Model.extend()').callee;
16-
expect(importUtils.getSourceModuleName(node)).toEqual('Model');
16+
expect(importUtils.getSourceModuleName(node)).toStrictEqual('Model');
1717
});
1818

1919
it('gets the correct module name with CallExpression', () => {
2020
const node = parse('Model.extend()');
21-
expect(importUtils.getSourceModuleName(node)).toEqual('Model');
21+
expect(importUtils.getSourceModuleName(node)).toStrictEqual('Model');
2222
});
2323
});

0 commit comments

Comments
 (0)