Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against key-less nodes. Fixes #71 #72

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0b4399a
Remove default BLACKLIST
lynchbomb Jul 26, 2017
c3bcdca
Update no-jquery-methods.md
lynchbomb Aug 2, 2017
03d470f
Check node type for lib/utils/imports.collectImportBindings
shamcode Aug 7, 2017
f392997
Update CHANGELOG and AUTHORS for 0.8.0
lynchbomb Aug 15, 2017
eafee52
0.8.0
lynchbomb Aug 15, 2017
30b6916
Implement rule for anonymous functions passed to scheduleOnce and once
eddie-ruva Aug 19, 2017
ac5df8a
Add linting for CallExpessions like $.ajax()
nlfurniss Aug 30, 2017
b94cdd3
Add doc explaining how to generate blacklist array
nlfurniss Aug 30, 2017
9a26687
Remove Ember from isJQueryCaller check
nlfurniss Aug 30, 2017
bb91826
Increase test coverage for no-jquery-methods and bump authors
nlfurniss Aug 30, 2017
e9d70a0
Guard propertyName in no-jquery-methods
nlfurniss Aug 30, 2017
9b3da80
Update CHANGELOG and AUTHORS for 0.9.0
lynchbomb Aug 31, 2017
55730db
0.9.0
lynchbomb Aug 31, 2017
8680be8
Create no-jquery-selector rule
nlfurniss Aug 31, 2017
7ece7fd
Fix logic to detect jQuery being assigned to a var
nlfurniss Sep 5, 2017
aaa7c0d
Fix no-global-jquery returning false positive for var assignment #85
nlfurniss Sep 6, 2017
68f8bc9
Rethink detecting global jquery var assignments
nlfurniss Sep 8, 2017
1eea3d6
Add fuctionality and tests for more global jquery cases
nlfurniss Sep 9, 2017
7957085
Handle local jquery vars in no-jquery-methods
nlfurniss Sep 11, 2017
5c3cdfc
Fix no-anonymous-once not recognizing context function
nlfurniss Sep 12, 2017
5815778
Update CHANGELOG for 1.0.0
nlfurniss Sep 13, 2017
ab5d1b1
1.0.0
Sep 13, 2017
a41bf53
DRY up `parserOptions`
nlfurniss Sep 14, 2017
d2a591c
Fixes require-ember-lifeline rule to scope it to only ember file type…
scalvert Oct 1, 2017
9e307f9
Add missing tests (#91)
hjdivad Oct 3, 2017
c66fddf
Update CHANGELOG and AUTHORS for 1.1.0
scalvert Oct 3, 2017
ab51a06
1.1.0
scalvert Oct 3, 2017
cb794cc
Add tests for jquery util methods (#90)
nlfurniss Nov 3, 2017
62071ae
[BUG FIX] Cannot read property `getFilename` of undefined
sangm Nov 12, 2017
5950e5e
Add 1.1.1 to the CHANGELOG.md and update AUTHORS.txt.
rwjblue Nov 13, 2017
475ffb1
v1.1.1
rwjblue Nov 13, 2017
0d29a19
Guard against key-less nodes. Fixes #71
mwpastore Jul 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix no-anonymous-once not recognizing context function
  • Loading branch information
nlfurniss authored and mwpastore committed Nov 29, 2017
commit 5c3cdfc7bc52cfd57fd4d7c08859e31bd06343f4
10 changes: 8 additions & 2 deletions lib/rules/no-anonymous-once.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
const { getCaller, cleanCaller, isCallingWithApply, isCallingWithCall } = require('../utils/caller');
const { collectObjectPatternBindings } = require('../utils/destructed-binding');
const { getEmberImportBinding } = require('../utils/imports');
const { get } = require('../utils/get');
const MESSAGE
= `The uniqueness once offers is based on function uniqueness, each invocation of this line will always create a new
function instance, resulting in uniqueness checks, that will never be hit. Please replace with a named function.
@@ -49,9 +50,14 @@ function normalizeArguments(caller, args) {

return mut;
}

/**
* Determines whether a function is anonymous based on whether it was a name
* or if it is a method on the current context.
* @param {ASTNode} fn
* @return {Boolean}
*/
function isAnonymousFunction(fn) {
return fn && !fn.name;
return !(get(fn, 'name') || get(fn, 'object.type') === 'ThisExpression');
}

function isString(node) {
70 changes: 70 additions & 0 deletions tests/lib/rules/no-anonymous-once.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,76 @@ ruleTester.run('no-anonymous-once', rule, {
run.once.call(this, noop);
}
});`
},
{
code: `
export default Ember.Component({
cb: () => {
// do stuff
},

perform() {
Ember.run.once(this, 'cb');
}
});`
},
{
code: `
export default Ember.Component({
cb: () => {
// do stuff
},

perform() {
Ember.run.once(this, this.cb);
}
});`
},
{
code: `
function cb() {
//do stuff
}
export default Ember.Component({
perform() {
Ember.run.once(this, cb);
}
});`
},
{
code: `
export default Ember.Component({
cb: () => {
// do stuff
},

perform() {
Ember.run.scheduleOnce('afterRender', this, 'cb');
}
});`
},
{
code: `
export default Ember.Component({
cb: () => {
// do stuff
},

perform() {
Ember.run.scheduleOnce('afterRender', this, this.cb);
}
});`
},
{
code: `
function cb() {
//do stuff
}
export default Ember.Component({
perform() {
Ember.run.scheduleOnce('afterRender', this, cb);
}
});`
}
],
invalid: [