Skip to content

Commit c55b8e0

Browse files
authored
Rule docs (#30)
* Adding/adjusting docs for rules. Adding comments and doc properties to all rules. Fixing broken links in rule messages.
1 parent 96156f5 commit c55b8e0

File tree

12 files changed

+112
-12
lines changed

12 files changed

+112
-12
lines changed
File renamed without changes.

lib/rules/no-timers.js renamed to lib/rules/linkedin/no-timers.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
const { isInActions, isInteractive } = require('../utils/interactive');
2-
const { isBrowser, isEnvironmentBrowser } = require('../utils/linkedin/bpr');
1+
/**
2+
* @fileOverview Disallow use of unguarded timers, which can result in issues within the BPR.
3+
* @author Steve Calvert
4+
*/
5+
6+
const { isInActions, isInteractive } = require('../../utils/interactive');
7+
const { isBrowser, isEnvironmentBrowser } = require('../../utils/linkedin/bpr');
38

49
const TIMERS = ['setTimeout', 'setInterval'];
510

6-
const MESSAGE = 'Do not use timers. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/files/guides/no-timers.md';
11+
const MESSAGE = 'Do not use timers. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/linkedin/no-timers.md';
712

813
function isTimer(name) {
914
return TIMERS.includes(name);
@@ -18,6 +23,11 @@ function getName(node) {
1823
}
1924

2025
module.exports = {
26+
docs: {
27+
description: 'Disallow use of unguarded timers, which can result in issues within the BPR',
28+
category: 'Best Practices',
29+
recommended: false
30+
},
2131
meta: {
2232
message: MESSAGE
2333
},

lib/rules/linkedin/no-unguarded-document.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const { isBrowser, isEnvironmentBrowser, getEnvironmentImportBinding } = require
99
const { isInActions, isInteractive } = require('../../utils/interactive');
1010
const { collectObjectPatternBindings } = require('../../utils/destructed-binding');
1111

12-
const MESSAGE = 'Do not use unguarded document references. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/files/guides/no-unguarded-document.md';
12+
const MESSAGE = 'Do not use unguarded document references. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/linkedin/no-unguarded-document.md';
1313

1414
/**
1515
* Determines if the current node is a document reference.
1616
* @param {ASTNode} node The identifier node.
17-
* @returns {Boolean} Returns true if a document reference is found, else false.
17+
* @returns {Boolean} Returns true if a document reference is found, otherwise false.
1818
*/
1919
function isDocumentReference(node) {
2020
return get(node, 'callee.object.name') === 'document';

lib/rules/linkedin/no-unguarded-window.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const { isBrowser, isEnvironmentBrowser, getEnvironmentImportBinding } = require
99
const { isInActions, isInteractive } = require('../../utils/interactive');
1010
const { collectObjectPatternBindings } = require('../../utils/destructed-binding');
1111

12-
const MESSAGE = 'Do not use unguarded window references. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/files/guides/no-unguarded-window.md';
12+
const MESSAGE = 'Do not use unguarded window references. Please see the following guide for more infromation: http://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/linkedin/no-unguarded-window.md';
1313

1414
/**
1515
* Determines if the current node is a window reference.
1616
* @param {ASTNode} node The identifier node.
17-
* @returns {Boolean} Returns true if a window reference is found, else false.
17+
* @returns {Boolean} Returns true if a window reference is found, otherwise false.
1818
*/
1919
function isWindowReference(node) {
2020
return get(node, 'object.name') === 'window';

lib/rules/no-2.0.0-hooks.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
/**
2+
* @fileOverview Don't use Ember 2.0.0 hooks.
3+
* @author Chad Hietala
4+
*/
5+
'use strict';
6+
17
// TODO
28
// Write docs for this once we feel it should be recommended.
39
const MESSAGE = 'Do not use the 2.0.0 hooks as they are not conducive to the programming model.';
410
const MISTAKE_HOOKS = ['didInitAttrs', 'didReceiveAttrs', 'didUpdateAttrs', 'didRender', 'willUpdate', 'didUpdate', 'willRender'];
511

612
module.exports = {
13+
docs: {
14+
description: 'Don\'t use Ember 2.0.0 hooks',
15+
category: 'Best Practices',
16+
recommended: false
17+
},
718
meta: {
819
message: MESSAGE
920
},

lib/rules/no-attrs-snapshot.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
/**
2+
* @fileOverview Disallow use of attrs snapshot in `didReceiveAttrs` and `didUpdateAttrs`.
3+
* @author Chad Hietala
4+
*/
5+
'use strict';
6+
17
const { get } = require('../utils/get');
28

9+
/**
10+
* Determines if `didReceiveAttrs` or `didUpdateAttrs` are recieving parameters. If so,
11+
* this indicates the `attrs` snapshots are being used within those methods.
12+
* @param {ASTNode} node The identifier node.
13+
* @returns {Boolean} Returns true if either `didReceiveAttrs` or `didUpdateAttrs` are utilizing
14+
* a parameter containing `attrs`, otherwise false.
15+
*/
316
function hasAttrsSnapShot(node) {
417
let methodName = get(node, 'parent.key.name');
518
let hasParams = node.params.length > 0;
@@ -9,6 +22,11 @@ function hasAttrsSnapShot(node) {
922
const MESSAGE = 'Do not use the attrs snapshot that is passed in `didReceiveAttrs` and `didUpdateAttrs`. Please see the following guide for more infromation: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-attrs-snapshot.md';
1023

1124
module.exports = {
25+
docs: {
26+
description: 'Disallow use of attrs snapshot in `didReceiveAttrs` and `didUpdateAttrs`',
27+
category: 'Best Practices',
28+
recommended: true
29+
},
1230
meta: {
1331
message: MESSAGE
1432
},

lib/rules/no-attrs.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
/**
2+
* @fileOverview Disallow the use of `this.attrs`.
3+
* @author Chad Hietala
4+
*/
5+
'use strict';
6+
7+
/**
8+
* Determines if this expression matches `this.attrs`.
9+
* @param {ASTNode} node The identifier node.
10+
* @returns {Boolean} Returns true if the expression matches, otherwise false.
11+
*/
112
function isAttrs(node) {
213
return node.property.name === 'attrs' && node.object.type === 'ThisExpression';
314
}
415

516
const MESSAGE = 'Do not use this.attrs. Please see the following guide for more infromation: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-attrs.md';
617

718
module.exports = {
19+
docs: {
20+
description: 'Disallow the use of `this.attrs`',
21+
category: 'Best Practices',
22+
recommended: true
23+
},
824
meta: {
925
message: MESSAGE
1026
},

lib/rules/no-lifecycle-events.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* @fileOverview Disallow use of lifecycle events using `.on()`.
3+
* @author Chad Hietala
4+
*/
5+
'use strict';
6+
7+
const { collectObjectPatternBindings } = require('../utils/destructed-binding');
8+
const { getEmberImportBinding } = require('../utils/imports');
9+
110
const MESSAGE = 'Do not use events for lifecycle hooks. Please use the actual hooks instead: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-lifecycle-events.md';
211

312
function isOn(node) {
@@ -8,18 +17,25 @@ function isEmber(node) {
817
return node.name === 'Ember';
918
}
1019

11-
const { collectObjectPatternBindings } = require('../utils/destructed-binding');
12-
const { getEmberImportBinding } = require('../utils/imports');
13-
1420
module.exports = {
21+
docs: {
22+
description: 'Disallow use of lifecycle events using `.on()`',
23+
category: 'Best Practices',
24+
recommended: true
25+
},
1526
meta: {
1627
message: MESSAGE
1728
},
1829
create(context) {
1930
var emberImportBinding;
2031
let destructedBindings = [];
32+
2133
return {
2234
ObjectPattern(node) {
35+
/**
36+
* Retrieves the deconstructed bindings from the Ember import, accounting for aliasing
37+
* of the import.
38+
*/
2339
if (emberImportBinding) {
2440
destructedBindings = destructedBindings.concat(collectObjectPatternBindings(node, {
2541
[emberImportBinding]: ['on']

lib/rules/no-observers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @fileOverview Disallow use of observers.
3+
* @author Chad Hietala
4+
*/
15
'use strict';
26

37
function isObserver(node) {
@@ -9,6 +13,11 @@ function isObserver(node) {
913
const MESSAGE = 'Do not use observers. Consider using computed properties instead. Please see following guide for more information: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-observers.md';
1014

1115
module.exports = {
16+
docs: {
17+
description: 'Disallow use of observers',
18+
category: 'Best Practices',
19+
recommended: true
20+
},
1221
meta: {
1322
message: MESSAGE
1423
},

lib/rules/no-side-effect-cp.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
/**
2+
* @fileOverview Disallow use of computed properties that include side-effect producing calls.
3+
* @author Chad Hietala
4+
*/
5+
16
const { getCaller, cleanCaller } = require('../utils/caller');
27
const isCPGetter = require('../utils/computed-property');
38
const { getEmberImportBinding, collectImportBindings } = require('../utils/imports');
49
const { collectObjectPatternBindings } = require('../utils/destructed-binding');
510

611
let SIDE_EFFECTS = ['this.send', 'this.sendAction', 'this.sendEvent', 'Em.sendEvent', 'Ember.sendEvent', 'this.trigger', 'this.set', 'Ember.set', 'Em.set', 'this.setProperties', 'Ember.setProperties', 'Em.setProperties'];
712

8-
const MESSAGE = 'Do not send events or actions in Computed Properties. This will cause data flow issues in the application, where the accessing of a property causes some side-effect. You should only send actions on behalf of user initiated events. Please see the following guide for more infromation: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-action-cp.md';
13+
const MESSAGE = 'Do not send events or actions in Computed Properties. This will cause data flow issues in the application, where the accessing of a property causes some side-effect. You should only send actions on behalf of user initiated events. Please see the following guide for more infromation: https://github.com/chadhietala/ember-best-practices/blob/master/guides/rules/no-side-effect-cp.md';
914

1015
module.exports = {
16+
docs: {
17+
description: 'Disallow use of computed properties that include side-effect producing calls',
18+
category: 'Best Practices',
19+
recommended: true
20+
},
1121
meta: {
1222
message: MESSAGE
1323
},

0 commit comments

Comments
 (0)