-
Notifications
You must be signed in to change notification settings - Fork 84
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
Rule UNUSED_LOCAL_VARIABLE has issues with several tags #339
Comments
These are implemented. Thanks for reporting it. |
Thanks a lot Ryan! Will test asap |
Sorry, this issue is not fixed with 1.2.0 - I still have lots of false positives
|
I'm assuming you meant:
I added @Datasource to the expressions that are considered, and fixed an issue with the variables scope. |
No, I didn't mean the datasource attribute - the name attribute is important. atm the rule returns false positives for:
|
@derrick13 , I would expect this to flag unused:
and this to NOT flag it:
Am I missing something? |
Hi Ryan,
see
https://luceeserver.atlassian.net/browse/LDEV-1130
One of the more poor design decisions in ColdFusion was to have the 'scopes' created by tags such as cfcatch cffile, and cfhttp (and for that matter, the name attribute of cfquery) go into the variables scope by default when called from the context of a method. I've seen a lot of code over the years with hard-to-detect bugs due to values bleeding into the variables scope.
Also cfloop index and item and other attributes.
|
I agree. The varscoper encourages this.
I'm just wondering, if any of these variables aren't actually dereferenced,
do we care? Or should we just ignore them all?
…On Tue, Jul 18, 2017 at 9:07 AM, Harry Klein ***@***.***> wrote:
Hi Ryan,
see
https://luceeserver.atlassian.net/browse/LDEV-1130
One of the more poor design decisions in ColdFusion was to have the
'scopes' created by tags such as cfcatch cffile, and cfhttp (and for that
matter, the name attribute of cfquery) go into the variables scope by
default when called from the context of a method. I've seen a lot of code
over the years with hard-to-detect bugs due to values bleeding into the
variables scope.
Also cfloop index and item and other attributes.
Von: ryaneberly ***@***.***
Gesendet: Dienstag, 18. Juli 2017 14:04
An: cflint/CFLint ***@***.***>
Cc: Harry Klein ***@***.***>; Mention ***@***.***>
Betreff: Re: [cflint/CFLint] Rule UNUSED_LOCAL_VARIABLE has issues with
several tags (#339)
@derrick13<https://github.com/derrick13> ,
Thanks, are you saying that when the query name is declared, we should
consider that variable used?
I would expect this to flag unused:
<cfset var qAllPages = "">
<cfquery name="qAllPages" datasource="#variables.
sPublishDataSource#">...</cfquery>
and this to NOT flag it:
<cfset var qAllPages = "">
<cfquery name="qAllPages" datasource="#variables.
sPublishDataSource#">...</cfquery>
<cfloop query="qAllPages">...</cfloop>
Am I missing something?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/
cflint/CFLint#339#issuecomment-316043208>, or mute the thread<
https://github.com/notifications/unsubscribe-auth/
AAWkYHkpnCPq3YD36etKEHVwSJZ1Ls7Aks5sPJ8igaJpZM4OPfpx>.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#339 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFtZu2QTibZXN7NPdV35f_Iiq3lYKsKfks5sPKyRgaJpZM4OPfpx>
.
|
Imho we could just ignore them all
|
As opposed to Ryan, I personally would treat both cases below as NOT flagging UNUSED_LOCAL_VARIABLE. To me it doesn't matter if you use qAllPages in a loop or output or whatever after the query - the mere fact that it's used as a name for the query should be enough to not kick off this rule.
|
@TheRealAgentK, I'm good with that. Don't want to ding someone for using a best practice that makes up for a coldfusion deficiency. |
@derrick13 , Still looking at the local struct issue. |
Here's some - but it'd be good if @derrick13 could verify those first. cfchart / name also: this is just what I could easily think of - most likely not exhaustive. |
@derrick13
is an interesting one. It was a false positive because local is a scope. The false positive is removed. However, it seems to me that initializing local is bad practice now that local is a scope. Thoughts? |
Your list is implemented. It is parameterized in cflint.definition.json. |
Wow, thanks for your work Ryan - and for the list Kai!
|
Found another one:
|
@ryaneberly "... it seems to me that initializing local is bad practice now that local is a scope ..." Definitely, it is bad practice now but some of our code is old and was written before ACF 9 (which introduced the local scope) See also: |
@derrick13 would it be valuable to add a different linting rule for the declaration of a "local" variable? |
imho it would just complicate the configuration, I wouldn't add a new rule |
@derrick13, thanks for the detailed research. Much appreciated. 1 &2 - parsing cfquery is dicey -- suggest 1.3.0 |
I guess 1-4 are all related to cfparser - not sure if it would be possible to use the integrated Lucee parser instead of cfparser? |
|
|
As far as using an engine's parser: Engine parsers (like Lucee) have a different set of concerns than linters and IDEs have, which basically rules them out, as they're pure runtime (id est, one error at a time), while we (linters/IDE parsers) have to kind of swallow errors and keep on chugging to be at all useful. That, and we want to know information that the engine parser doesn't care about-- variable names, what's scoped where, etc., etc.. |
@derrick13 Does it work for you now that the dev trunk is using cfparser 2.4.10? |
@ryaneberly I updated my version and now the log issue is gone. |
@derrick13 Thanks for confirming. |
CFLint return the error message: local variable X is not used in function Y
But the local variables are used in tags like cfloop, cflocation, cfcookie, ...:
The text was updated successfully, but these errors were encountered: