Giter Site home page Giter Site logo

cflint / cflint Goto Github PK

View Code? Open in Web Editor NEW
171.0 34.0 79.0 13.71 MB

Static code analysis for CFML (a linter)

License: BSD 3-Clause "New" or "Revised" License

Java 89.94% XSLT 4.48% ColdFusion 5.43% Roff 0.02% Shell 0.03% Dockerfile 0.05% Mustache 0.04%
linter lint findbugs cfml coldfusion lucee static-code-analysis static-analysis code-quality

cflint's Introduction

CFLint

CFLint

Maven Central License Codacy Badge Build Status

A static code analysis tool for CFML.

License: BSD

Current Version: 1.5.x

Versions

See CHANGELOG.md for further information.

Project and library organization

CFLint is a project developed and worked on by volunteers. When logging issues please, be nice and considerate. We're here to help. We really appreciate fixes and improvements, so feel free to talk to us and/or provide pull requests.

/src/main contains the source code. Tests can be found in /src/test. CFLint relies heavily on the CFParser project as well as a bunch of third-party Java libraries.

The master branch is considered our stable codebase. Most of the development happens in the dev branch resp. local development branches for specific issues.

Building CFLint

  1. Fork the repository into your account and clone or download the codebase as a zip-file.

  2. Install the tooling of your choice and build via Gradle or Maven (deprecated). CFLint requires Java 8.

    a. Gradle: execute

     gradlew build
    

    in the cflint directory

    b. Maven: execute

     mvn clean install
    

    in the cflint directory

    Alternatively, import the CFLint codebase into the IDE of your choice and use its respectively Gradle/Maven integration. This should work out of the box for Eclipse and IntelliJ users.

Using CFLint - Quickstart Guide

Get the latest version from Maven Central or the CFLint GitHub release page or build the project.

If you want to use CFLint from within another Maven project, use:

<dependency>
    <groupId>com.github.cflint</groupId>
    <artifactId>CFLint</artifactId>
    <version>1.4.0</version>
</dependency>

Or always use the latest:

<dependency>
    <groupId>com.github.cflint</groupId>
    <artifactId>CFLint</artifactId>
    <version>LATEST</version>
</dependency>

With the binaries retrieved one or the other way, you can now use CFLint on the command line.

Use the "-all"-version of the jar-file

CFLint-1.5.0-all.jar

Scan a folder with the complete set of rules

java -jar CFLint-1.5.0-all.jar -folder <baseFolder>

Scan a file with the complete set of rules

java -jar CFLint-1.5.0-all.jar -file <fullPathToFile>

See command line parameters and help

java -jar CFLint-1.5.0-all.jar -help

User manual

Note: This is a work in progress, we're currently collating information from a variety of sources.

Introduction

The simplest options for executing CFLint is via the command line. CFLint currently has a UI mode (triggered by -ui on the command line) which will be removed by the latest for CFLint 2.0 - see Issue #316. If you rely on the UI mode, you're unfortunately on your own - no more work will go into this from here onwards.

Configuration

Alternatively to the command line, you can put .cflintrc files into certain directories. Configuring CFLint this way conceptually allows you to run specific rules in specific parts of your application.

CFLint currently supports JSON- and XML-based configuration. XML-based configuration is deprecated in CFLint 1.3.0 and will be removed in CFLint 2.0.

Rules

When CFLint executes, it scans and parses your code (using CFParser). The syntax tree is then being examined against a set of built-in rules.

In CFLint, those rules are called and implemented as plugins (they live in /src/main/java/com/cflint/plugins). By default, all rules will be used against your codebase. This is what a lot of people will do, but using configuration allows you to build a custom scenario to test your code against. See RULES.md for more information on rules and their meaning.

CFLint is opinionated and every release after 1.3.0 will never scan in directories starting with a . to prevent wasting time of hidden directories such as build configuration, module/library storage or version control information.

Global configuration

The default and global configuration file is /src/main/resources/cflint.definition.json. Common usage of CFLint usually does not require replacing this file.

Folder-based configuration

Putting a .cflintrc file into a directory allows you to specify certain rules that should be executed for this directory and its children. Additionally, you can specify a handful of other properties.

An example .cflintrc file is shown below:

{
    "rule": [ ],
    "excludes": [ ],
    "includes": [ {
        "code": "FUNCTION_HINT_MISSING"
    } ],
    "inheritParent": false,
    "parameters": { }
}
  • rule allows you add a plugin for this folder that is not listed in the global configuration. See ruleImpl in cflint.definition.json for examples.

  • excludes and includes allow you to specify an array of objects describing rules you want to be applied for this directory and its children. In the example above, the only rule to be checked for will be FUNCTION_HINT_MISSING.

  • inheritParent configures if the rules set in the global or any parent configuration should be inherited as a base set of rules.

  • parameters allows configuration of rules. See RULES.md for the parameters of each rule and their defaults. You must precede the parameter name with the rule name separated by a dot.

  • Please note: inheritPlugins and output were marked deprecated in CFLint 1.2.0 and removed in 1.4.0. Plugin inheritance is now always treated as true since the team cannot see a use case in which it should be disabled. The output type can be controlled elsewhere, such as command-line flags.

We provide a schema with the deprecated properties excluded.

See Recipes for some usage examples of .cflintrc. Example files can be found by browsing the project test files.

Annotation-based configuration

Quite often there are scenarios in which you would generally want to run a certain set of rules against your code but in specific cases need to ignore an otherwise valid violation.

A common example are violations of CFQUERYPARAM_REQ that can't be fixed by applying <cfqueryparam> because your DB server doesn't allow params in certain positions (for instance in a SELECT something FROM #application.config.linkedServerName#.DefaultDatabase.dbo.Comment scenario). See Issue #282 for more examples.

CFLint offers an annotation-based configuration to deal with this and similar scenarios. Annotations can be placed on the component- or function-level in a CFC or inline with code.

Tag-based CFML

<!---
@CFLintIgnore SOMETHINGELSE,MISSING_VAR,ANOTHERTHINGTOIGNORE
--->

CFScript

Ignoring all rules on the current line:

//cflint ignore:line

Ignoring a specific rule (or a comma-separated list of rules) on the current line:

//cflint ignore:MISSING_VAR

Multiline ignore annotation:

/*
    @CFLintIgnore SOMETHINGELSE,MISSING_VAR,ANOTHERTHINGTOIGNORE
*/

Ignoring within SQL

Within SQL, you can also use

<!--- @CFLintIgnore CFQUERYPARAM_REQ --->

to ignore a rule violation on the next line.

Precedence of configuration settings

Configuration of which plugins are run and which rules are included starts with the global configuration and flows through the command line parameters, folder level rules, and down to the annotations within the source.

  • global configuration
  • custom configuration file (-configfile, we do not encourage this option to be used in day-to-day operations of CFLint)
  • rule groups (-rulegroups, default behavior is --rulegroups !Experimental)
  • includes/excludes from the command line (-includeRule and -excludeRule)
  • .cflintrc - folder level configuration, mostly for including/excluding specific messages
  • annotations - explicitly exclude messages in the source code at the tag or line level.

The configuration rule that is closest to the rule is the one that takes effect.

  • If an annotation excludes a message, it will not fire regardless of any configuration above it.
  • If you exclude a rule at the command line level, but a .cflintrc adds it back in, it will fire for source files in that part of the source tree.
  • If you are passing in multiple parameters at the command line level, in Windows Powershell the parameters must be included in "double quotes", e.g. -includeRule "MISSING_VAR,CFQUERYPARAM_REQ"

Creating reports

CFLint supports a variety of reporting and output options that you can control via command-line flags. Beyond the targeted output formats of Text, XML, JSON or HTML you can also run CFLint with options for quiet, verbose and debug output.

If no targeted output format is specified at all, CFLint will default to creating an HTML report in the file cflint-result.html.

Execution modes

You can force CFLint's output behavior to stdout and stderr by specifying options for quiet, verbose and debug. If you do not specify either, CFlint will return basic internal information and error output to stdout and stderr.

Quiet

Quiet mode (-quiet <boolean>) suppresses most of the output CFLint would otherwise create during linting. This might contain actual errors and exceptions but also information like the termination of recursive template parsing or certain configuration issues. Do not run quiet mode if you likely will need assistance with error messages or want to understand better what CFLint is doing.

This is the minimum output mode you can run CFLint in and the feature was originally inspired by Issue #4.

There might be occasional messages from CFParser and ANTLR being pushed into stderr at this stage - even though CFlint runs in quiet mode. This is a known issue and will be addressed in the future.

Verbose

Verbose mode (-verbose <boolean>) enables verbose linting output. This contains information on selected output formats and configuration files being found and processes during linting as well as the currently processed file CFLint is working on (showing only files that are actually scanned).

If you want more information about the inner workings of CFLint during execution, verbose mode is the minimum you should run CFLint in.

Debug

Debug mode (-debug <boolean>) enables debug output. Debug mode implies verbose mode but adds additional information such as the parser tokens and every processed file (regardless of being supported by your or the default extension list) into the output streams.

Precedence

It is possible to switch on and run quiet, verbose and debug modes together at the same time. This is partly intended as you might not want to see error information being suppressed by quiet mode, but still want so see certain information being shown in verbose mode. Please take this behavior with a grain of salt though - there might be the odd scenario in which combining -quiet, -verbose and -debug causes unusual output.

The exception is debug mode. In debug mode, CFLint will always ignore user settings for verbose and quiet and set verbose to true and quiet to false.

HTML

The flag -html instructs CFLint to create an HTML document. The full syntax is:

-html -html <outputFileName>

XML

The flag -xml instructs CFLint to create XML. There are two options for XML reporting.

The first option is what we call CFLint XML. It's an internal format that adheres to a basic schema provided here. You could then use this format as-is or to do further processing of your choice.

The second option is FindBugs XML. The resulting XML document adheres to the current version of the FindBugs BugCollection XML Schema Definition and can be used in most CI-/Build-Server products. JetBrains TeamCity 10+ can import this format out of the box.

Please note: Currently it's not possible to produce BOTH flavors of XML reports at the same time. This is a known limitation. This limitation will be removed as part of CFLint 2.0 (see Issue #331).

CFLint XML

To create CFLint XML provide the following command-line arguments:

-xml -xmlstyle cflint -xmlfile <outputFileName>

Example of CFLint XML:

<?xml version="1.0" encoding="UTF-8" ?>
<issues version="1.2.1" timestamp="1500107134">
    <issue severity="WARNING" id="CFQUERYPARAM_REQ" message="CFQUERYPARAM_REQ" category="CFLint" abbrev="CR">
        <location file="/Users/kai/Documents/Code/paypal.cfc" fileName="paypal.cfc" function="doSomething" column="0" line="325" message="&lt;cfquery&gt; should use &lt;cfqueryparam/&gt; for variable 'arguments.PaymentType'." variable="arguments.PaymentType">
            <Expression><![CDATA[<cfquery name="doPayment" datasource="#paymentDatasource#">...some more Details...]]></Expression>
        </location>
    </issue>
    <issue severity="WARNING" id="CFQUERYPARAM_REQ" message="CFQUERYPARAM_REQ" category="CFLint" abbrev="CR">
        <location file="/Users/kai/Documents/Code/paypal.cfc" fileName="paypal.cfc" function="doSomethingElse" column="0" line="432" message="&lt;cfquery&gt; should use &lt;cfqueryparam/&gt; for variable 'arguments.something'." variable="arguments.something">
            <Expression><![CDATA[<cfquery name="doPayment" datasource="#paymentDatasource#">...some more Details...]]></Expression>
        </location>
    </issue>
...
    <counts totalfiles="108" totallines="55596">
        <count code="CFQUERYPARAM_REQ" count="39"></count>
        <count severity="WARNING" count="39"></count>
    </counts>
</issues>

FindBugs XML

To create FindBugs XML provide the following command-line arguments:

-xml -xmlstyle findbugs -xmlfile <outputFileName>

The FindBugs XML format is currently created using an XSLT document, transforming the CFLint report to FindBugs XML (/src/main/resources/findbugs/cflint-to-findbugs.xsl).

JSON

JSON output can be created with

-json -jsonfile <outputFileName>

Example of CFLint JSON:

{
    "version" : "1.2.1",
    "timestamp" : 1501202128,
    "issues" : [ {
        "severity" : "ERROR",
        "id" : "MISSING_VAR",
        "message" : "MISSING_VAR",
        "category" : "CFLINT",
        "abbrev" : "MV",
        "locations" : [ {
            "file" : "src/test/resources/com/cflint/tests/Ignores/ignoreCFMLAny2.cfc",
            "fileName" : "ignoreCFMLAny2.cfc",
            "function" : "testFunction",
            "column" : 6,
            "line" : 14,
            "message" : "Variable someVar is not declared with a var statement.",
            "variable" : "someVar",
            "expression" : "someVar"
        } ]
    } ],
    "counts" : {
        "totalFiles" : 7,
        "totalLines" : 49,
        "countByCode" : [ {
            "code" : "MISSING_VAR",
            "count" : 1
        } ],
        "countBySeverity" : [ {
            "severity" : "ERROR",
            "count" : 1
        } ]
    }
}

The JSON schema is available here.

Text

Plain text output can be created with

-text -textfile <outputFileName>

Example of plain text output:

Issue
Severity:WARNING
Message code:CFQUERYPARAM_REQ
    File:/Users/kai/Documents/Code/paypal.cfc
    Column:0
    Line:79
        Message:<cfquery> should use <cfqueryparam/> for variable 'arguments.something'.
        Variable:'arguments.something' in function:
        Expression:<cfquery name=\"qry\" datasource=\"#variables.dsn#\" cachedwithin=\"#createTimeSpan(0,0,arguments.cacheInMins,0)#\">\r\n...some Details...

Severity:WARNING
Message code:CFQUERYPARAM_REQ
    File:/Users/kai/Documents/Code/paypal.cfc
    Column:0
    Line:145
        Message:<cfquery> should use <cfqueryparam/> for variable 'arguments.something'.
        Variable:'arguments.something' in function:
        Expression:<cfquery name=\"qry\" datasource=\"#variables.dsn#\" cachedwithin=\"#createTimeSpan(0,0,arguments.cacheInMins,0)#\">\r\n...some Details...

...


Total files:108
Total lines:55690

Issue counts:1
CFQUERYPARAM_REQ:4

Total issues:4
Total warnings:4

API

To interact directly with CFLint within the JVM use the CFLint API.

import com.cflint.api.CFLintAPI;
import com.cflint.api.CFLintResult;

CFLintAPI api = new CFLintAPI();
CFLintResult result = api.scan(filename);
String jsonResult = result.getJSON();

Integration server support

For Jenkins, please look at the Jenkins/Hudson plugin mentioned further below.

JetBrains' TeamCity has support for FindBugs XML code inspection reports. They can be produced out of the box with CFLint from 1.2.0 onwards (see above in the FindBugs XML section).

There is support for SonarQube through StepStone's Sonar ColdFusion plugin mentioned further below.

For Azure DevOps/TFS, please look at the Azure Pipeline/TFS Build extension mentioned further below.

There's an NPM wrapper for CFLint below. Please be aware that the wrapper seems to come with its own bundled CFLint binary which might not be up-to-date, which is outside of our control.

Other products in the integration/build server category might work, too. If you're using a specific product that works for you with CFLint, please let us know. If you can't get CFLint to work in an environment you use, please let us know as well - we might be able to help.

IDE support

There are several IDE integrations for CFLint that are available. Below are some brief descriptions, but if you'd like to know more, see Interesting third-party projects.

There is IDE support for Sublime Text 3 through a third-party project utilizing SublimeLinter.

There is also support for Adobe ColdFusion Builder through a third-party project. Users of CFBuilder, please also see the discussion in Issue #327.

Users of Atom can integrate via AtomLinter through a third-party project.

An extension for Visual Studio Code is also available as a third-party project.

Support for JetBrains' IntelliJ is available as third-party plugin.

Extending CFLint

Adding custom rules

package com.cflint.plugins.core;

import net.htmlparser.jericho.Element;
import cfml.parsing.cfscript.script.CFFuncDeclStatement;
import cfml.parsing.cfscript.script.CFFunctionParameter;
import cfml.parsing.cfscript.script.CFScriptStatement;

import com.cflint.BugList;
import com.cflint.plugins.CFLintScannerAdapter;
import com.cflint.plugins.Context;
import com.cflint.tools.CFTool;

public class ArgDefChecker extends CFLintScannerAdapter {

    @Override
    public void expression(final CFScriptStatement expression, final Context context, final BugList bugs) {
        if (expression instanceof CFFuncDeclStatement) {
            final CFFuncDeclStatement function = (CFFuncDeclStatement) expression;
            for (final CFFunctionParameter argument : function.getFormals()) {
                // handler.addArgument(param.getName());
                final String name = argument.getName();
                if (!argument.toString().contains("required") && !argument.toString().contains("=")) {
                    function.getLine();
                    function.getColumn();
                    context.addMessage("ARG_DEFAULT_MISSING", name);
                }
            }
        }
    }

    @Override
    public void element(final Element element, final Context context, final BugList bugs) {
        if (element.getName().equals("cfargument")) {
            final String name = element.getAttributeValue("name");
            final boolean required = CFTool.toBoolean(element.getAttributeValue("required"));
            final String defaultExpr = element.getAttributeValue("default");
            if (!required && defaultExpr == null) {
                element.getSource().getRow(element.getBegin());
                element.getSource().getColumn(element.getBegin());
                context.addMessage("ARG_DEFAULT_MISSING", name);
            }
        }
    }
}

Looking at the function element, the arguments are:

  • element - the current CFML tag
  • context - the current file being checked
  • bugs - the appending object of violations

Recipes

Ignoring a directory for processing

The easiest way to achieve this is with a custom .cflintrc file:

The includes field is ignored if it is an empty list, so simply add a single item to it for which nothing matches.

{
    "code" : "NOTHING"
}

or more simply:

    {}

The following will ignore all rules in the current folder and below.

{
    "rule" : [ ],
    "excludes" : [ ],
    "includes" : [ {} ],
    "inheritParent" : false,
    "parameters" : {}
}

This can be simplified using the default values of a .cflintrc file:

{
    "includes" : [{}],
    "inheritParent" : false
}

See the discussion in Issue #290 for more info.

Configuring a parameter

Parameters within the rules can be overridden in the .cflintrc files. Use the rule name and the parameter joined with a dot.

{
    "parameters" : {
        "VariableNameChecker.maxLength": "15"
    }
}

Filtering out specific processing results in specific folders

Supply a cflintexclude.json file in the command line with the -filterFile argument.

Examples

To filter out the GLOBAL_VAR messages in the "some\package\location" folder, add the following to cflintexclude.json

Windows

[
    other exclude rules...,
    {"file":".*some\\\\package\\\\location\\\\.*","code":"GLOBAL_VAR"}
]

Note: The back slashes must be escaped twice, once for JSON, once for regular expressions

*nix

[
    other exclude rules...,
    {"file":".*some/package/location/.*","code":"GLOBAL_VAR"}
]

Support

Raise issues here on GitHub and we will look at them.

The CFML Slack team has a #cflint channel you can join and talk to most of the regular contributors and other users.

How to contribute

See CONTRIBUTING.md for further information.

Interesting third-party projects

Please note that the majority of the libraries and projects mentioned here are not directly related to and maintained by the CFLint team. Please see the authors and maintainers of the respective project for support using their libraries first.

If you have been working on (or are thinking about starting) a project related to CFLint, please let us know. We're happy to include relevant third-party projects to the list above.

cflint's People

Contributors

andyj avatar antoinegagnon avatar aymandf avatar cameroncf avatar codacy-badger avatar denuno avatar dependabot[bot] avatar displague avatar eberlyrh avatar edbartram avatar ilaeria avatar isaac-mercieca avatar jerronjames avatar jjames967 avatar joshknutson avatar jsteinshouer avatar justinmclean avatar kamasamak avatar mpaluchowski avatar msp1kpj avatar playedinane avatar pr1st0n avatar ryaneberly avatar sjmatta avatar t-rav avatar therealagentk avatar tstec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cflint's Issues

maven build instructions should address common distribution requirements

Are there more complete build instructions that can be provided for people that don't live and breath Java builds?

On a vanilla debian install,apt-get install default-jdk maven followed by cloning the repo and running maven clean install yields the following errors: https://gist.github.com/displague/702f0405bfa932be5778

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project CFLint: Compilation failure: Compilation failure:
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/config/ConfigUtils.java:[47,2] error: annotations are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/config/ConfigUtils.java:[48,15] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/config/ConfigUtils.java:[78,28] error: for-each loops are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable for-each loops)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/plugins/core/QueryParamChecker.java:[18,2] error: annotations are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/plugins/core/QueryParamChecker.java:[23,39] error: for-each loops are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable for-each loops)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/plugins/core/VarScoper.java:[19,2] error: annotations are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/plugins/core/VarScoper.java:[50,4] error: generics are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/plugins/core/VarScoper.java:[63,31] error: for-each loops are not supported in -source 1.3
[ERROR] 
[ERROR] (use -source 5 or higher to enable for-each loops)
[ERROR] /home/displague/src/CFLint/src/main/java/com/cflint/CFLint.java:[71,5] error: generics are not supported in -source 1.3

... And more in the gist

does not support tagless components

does not support tagless components.

does not lint:

component accessors=true {
public name function init(){
return this;
}

public void function test(){
myvar = "test";
}
}

will lint the tag version.

It would be useful to have a -q (--quiet) option

This currently happens:

$ cflint -folder images -text -textfile /dev/stdout 

Option folder => images
Option text => null
Option textfile => /dev/stdout
htmloutput?false
xmlOutput?false
Writing /dev/stdout

Total issues:0

It would be useful to be able to turn off the printing of all progress/debug/error indicators. I'd be inclined to print them to stderr instead so they can be redirected out of the way, though it would be quicker to check for -q so they aren't printed in the first place.

This is so that ideally there would be a minimum amount of "noise" when calling cflint from a BufWritePost hook in vim for automatically linting CFML.

Convert bugs.add() to a plugin format.

I’d kind of like to get all “bugs.add(..)” removed from the CFLint.java file and set up as a separate plugins. Do you think you could take care of that when you get back?

License

What is the license for use of this tool? Many larger companies will not allow usage of tools without understanding what license governs its use.

Maven build fails with error.

Building as per instructions fails with the following error on a clean install of Maven, and cflint. jdk1.8.0_25:

Results :

Failed tests: testFunctionDef(com.cflint.TestCFBugs_OutputDef): expected:<...have @output='false'[ ]> but was:<...have @output='false'[]>

Tests run: 137, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:34 min
[INFO] Finished at: 2014-12-30T17:54:37-05:00
[INFO] Final Memory: 25M/124M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project CFLint: There are test failures.
[ERROR]
[ERROR] Please refer to C:\CFLint\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Multiple exceptions in output

Not sure why, but I get multiple exceptions when running over a folder.

-------cfml.parsing.cfscript.CFParseException: mismatched input '!' expecting RIGHTPAREN
org.antlr.runtime.tree.RewriteEmptyStreamException: rule primaryExpression
at org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:157)
at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(RewriteRuleElementStream.java:144)
at cfml.parsing.cfscript.CFScriptParser.memberExpressionB(CFScriptParser.java:16378)
at cfml.parsing.cfscript.CFScriptParser.memberExpression(CFScriptParser.java:16253)
at cfml.parsing.cfscript.CFScriptParser.unaryExpression(CFScriptParser.java:16136)
at cfml.parsing.cfscript.CFScriptParser.powerOfExpression(CFScriptParser.java:14837)
at cfml.parsing.cfscript.CFScriptParser.multiplicativeExpression(CFScriptParser.java:14685)
at cfml.parsing.cfscript.CFScriptParser.intDivisionExpression(CFScriptParser.java:14572)
at cfml.parsing.cfscript.CFScriptParser.modExpression(CFScriptParser.java:14450)
at cfml.parsing.cfscript.CFScriptParser.additiveExpression(CFScriptParser.java:14304)
at cfml.parsing.cfscript.CFScriptParser.concatenationExpression(CFScriptParser.java:14191)
at cfml.parsing.cfscript.CFScriptParser.equalityExpression(CFScriptParser.java:12382)
at cfml.parsing.cfscript.CFScriptParser.notExpression(CFScriptParser.java:12304)
at cfml.parsing.cfscript.CFScriptParser.andExpression(CFScriptParser.java:12141)
at cfml.parsing.cfscript.CFScriptParser.orExpression(CFScriptParser.java:12019)
at cfml.parsing.cfscript.CFScriptParser.xorExpression(CFScriptParser.java:11908)
at cfml.parsing.cfscript.CFScriptParser.equivalentExpression(CFScriptParser.java:11797)
at cfml.parsing.cfscript.CFScriptParser.impliesExpression(CFScriptParser.java:11549)
at cfml.parsing.cfscript.CFScriptParser.assignmentExpression(CFScriptParser.java:10662)
at cfml.parsing.cfscript.CFScriptParser.localAssignmentExpression(CFScriptParser.java:10588)
at cfml.parsing.cfscript.CFScriptParser.statement(CFScriptParser.java:4528)
at cfml.parsing.cfscript.CFScriptParser.compoundStatement(CFScriptParser.java:4126)
at cfml.parsing.cfscript.CFScriptParser.functionDeclaration(CFScriptParser.java:1888)
at cfml.parsing.cfscript.CFScriptParser.element(CFScriptParser.java:1605)
at cfml.parsing.cfscript.CFScriptParser.componentGuts(CFScriptParser.java:4238)
at cfml.parsing.cfscript.CFScriptParser.componentDeclaration(CFScriptParser.java:678)
at cfml.parsing.cfscript.CFScriptParser.scriptBlock(CFScriptParser.java:524)
at cfml.parsing.CFMLParser.parseScript(CFMLParser.java:315)
at com.cflint.CFLint.process(CFLint.java:147)
at com.cflint.CFLint.scan(CFLint.java:109)
at com.cflint.CFLint.scan(CFLint.java:103)
at com.cflint.CFLint.scan(CFLint.java:103)
at com.cflint.CFLint.scan(CFLint.java:103)
at com.cflint.CFLint.scan(CFLint.java:103)
at com.cflint.CFLint.scan(CFLint.java:103)
at com.cflint.CFLint.scan(CFLint.java:97)
at com.cflint.main.CFLintMain.execute(CFLintMain.java:242)
at com.cflint.main.CFLintMain.main(CFLintMain.java:157)

Exclude WEB-INF folder

I want to ignore the WEB-INF folder created by Railo under my wwwroot folder. Is this possible?

Add -version flag

Hi Ryan,
Would you be willing to add a -version flag to output the current version of CFLint to stdout?

Default cflintexclude.json should only ignore MISSING_VAR's in init() functions, other violations should NOT be ignored

Change the file etc/cflintexclude.json, to only ignore MISSING_VAR in the init function -- since setting component level variables is a normal task for the init function. However, I believe all the other rules should be enforced within the init() function.

Also, putting the documentation (or a cookbook/recipe) on how to use cflintexclude.json in the wiki would be good for users.

See some basic exclude documentation on Issue #24

Failed to execute goal on project CFLint: Could not resolve dependencies

Trying to install on Windows...

I've downloaded Maven and have it in C:\maven\bin

I ran the mvn clean install and it downloads a bunch of things from maven.apache.org (or correctly dumps them in my .m2 directory it appears) but then it bombs with:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.764 s
[INFO] Finished at: 2015-03-02T08:04:31-05:00
[INFO] Final Memory: 11M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project CFLint: Could not resolve dependencies
for project com.cflint:CFLint:jar:0.1.9: Failed to collect dependencies at com.
cfparser:cfml.parsing:jar:1.0.0: Failed to read artifact descriptor for com.cfpa
rser:cfml.parsing:jar:1.0.0: Could not find artifact com.cfparser:cfparser:pom:1
.0.0 in cfparser (https://raw.github.com/cfparser/cfparser/mvn-repo/) -> [Help 1
]

And this doesn't seem to exist:
https://raw.github.com/cfparser/cfparser/mvn-repo/

Am I doing something stupid or has something moved? :)

Thanks!
Jim

CFLint-ui asking for 4G of Memory

Using a computer with a smaller amount RAM, I'm getting an error:

"Invalid maximum heap size: -Xmx4g
The specified size exceeds the maximum representable size."

This is generated in the cflint-ui.bat file. I think it may be wise to let the system and Java negotiate RAM space. Perhaps even starting the heap size at 512M of memory of memory. Perhaps even smaller.

Vim syntastic support

I've seen references to people using vim sytantastic integration with cflint but can't find any pointers.

It would be great if the documentation included instructions (or config files) to make this simpler.

I think cflint may need a more terse and predictable output format for vim to latch on to line specific errors, but that may just be my ignorance (|grep|sed may do the trick).

I've been using this, but it is ugly:

~/.vim/ftplugin/cf.vim

function! Lint()
    ! /home/marques/.local/bin/cflint -file "%" -text
    cwindow
endfunction

if !exists("autocommands_loaded")
    let autocommands_loaded = 1
    autocmd BufWritePost *.cfm,*.cfc call Lint()
endif
" noremap <leader>l :w!<CR>:!clear;/home/marques/.local/bin/cflint -file "%" -text<CR>

Typo in read me (and logo)

In the readme on the repo's front page, you have

Cold Fusion

which is not the name of the language. I know it may sound silly, but you really should be using

ColdFusion (no space)

Also, the logo has Coldfusion, which isn't right either.

NESTED_CFOUTPUT false positive

        <cfoutput query="qryPopups" group="id">
            <cfif message NEQ "" and not(ListFind(arraytoList( arguments.quote.getErrorHandler().getShownErrors()),id))>
                <cfoutput>#message####id#|</cfoutput>
                <cfset arrayappend(arguments.quote.getErrorHandler().getShownErrors(),id)>
            </cfif>
            <cflog file="Quote_#quote.getOnlineNumber()#" text="Popup:#message#,#id#" type="informational">
        </cfoutput>

Lint Error Question

Hello I am testing CFLint for use on my code and the following CFC gives me a FILE_ERROR. In the report it states the following:

In file /EntityDefaults.cfc, line 0
In EntityDefaults.cfc
At line : 0
Expression:

and in Sublime I see this:

screen shot 2014-08-17 at 2 34 11 pm

The code is as follows:

/**
* @output           false
* @mappedSuperClass true
* @hint             I define common properties/methods and can be extended by other ORM component
*/
component
{
    // log defaults per table (handled by ormEventhandler)
    property name="createdOn"   ormtype="timestamp" notnull="true";
    property name="updatedOn"   ormtype="timestamp";

    private string function cleanEmoji(required string value){
        local.gotourl   = "http" & (application.useSSL ? "s" : "") & "://" & application.app_domain & "/clean-emoji.php";
        local.php       = new http(url:gotourl,method:"post");
        local.php.addParam(type:"formfield",name:"value",value:arguments.value);
        return trim(local.php.send().getPrefix().fileContent);
    }
}

Any explanation would be greatly appreciated

cflint --version returns error

After finally figuring out where the compiled files and bat files were, it will process correctly, but using the command cflint --version (or cflint -version) returns the following error:
Exception in thread "main" java.lang.NullPointerException
at com.cflint.Version.getVersion(Version.java:23)
at com.cflint.main.CFLintMain.main(CFLintMain.java:102)

CFLint 0.2.0, Windows 7 (64bit), Java 1.8.0_25

Arch Linux AUR

If any of you are archers, I created the package "cflint-git" in the AUR!

Specifying -textfile as an argument, implies -text should be set.

Currently I have to explicitly specify something like:

$ cflint -v -folder=blocks -text -textfile /dev/stdout 

Including -text as an argument is redundant, and shouldn't be required.

Similarly specifying -htmlfile or -htmlstyle imply html output is desired, so -html shouldn't need to be specified.

GPG error on mvn clean install

Keep getting a MojoExecutionException error due to Maven not being able to grab dependency: org.apache.maven.plugins:maven-gpg-plugin

"import" statement breaks parsing for scripted components

If I add an import statement to the top of my CFC file I start getting all sorts of parse errors that don't make sense:

line 6:10 no viable alternative at input 'componentextends'
Stage 2!
line 6:10 no viable alternative at input 'componentextends'
line 6:42 missing ';' at 'accessors'
line 7:0 missing ';' at '{'
line 16:8 no viable alternative at input 'publicvoid'
line 18:16 extraneous input 'SomeComponent' expecting {CONTAINS, GT, GTE, LTE, LT, EQ, NEQ, OR, EQV, XOR, AND, '.', ';', '||', '&&', '[', '?'}

Here is an example file:

import my.path.SomeComponent;

/**
* Hello world.
*/
component extends="my.path.BaseComponent" accessors="true"
{


    /**
    * @type string
    */
    property name="myProp";


    public void function myFunc1()
    {
        var foo = new SomeComponent;
    }


}

If I remove the import statement it works just fine. This is however valid CFML.

Speeding up CFLint

Do you have any suggestions for speeding up CFLint? I would really like to use it as part of the SublimeLinter package but with the lint mode set to background every time I save a file I get the spinning beach ball for a few seconds and the user interface is frozen. Presumably the plugin is running cflint and waiting for that to return which ties up the user interface. I base this assumption on when I run CFLint from the command line it takes about the same amount of time to process the file as the interface is frozen when I save.

Lint of cfprocresult fails in function when array is used.

The following cfprocresult will flag as an error even though it shouldn't: (Note code reduced for clarity)

<cfset var myRet = [] />

<cfstoredproc ...>
   <cfprocresult name="myRet[1]" resultset="1" />
   <cfprocresult name="myRet[2]" resultset="2" />
   <cfprocresult name="myRet[3]" resultset="3" />
</cfstoredproc>

The error given is Variable myRet[1] is not declared with a var statement. (only listing one of three).

parse error "can't look backwards more than one token in this stream"

var user = userservice"getuser"; --doesn't work
var user = userservice.getuser(); --works

The above 2 lines are both fine syntax. But the first line gives the parse error "can't look backwards more than one token in this stream". I can't use the 2nd line, because I use a variable within the brackets.

Is it possible to add my own excludeRule?
For instance with a regular expression .*

Mac OSX 10.9.4 Good build can not find

Good build with the following
mvn -e-X -Dgpg.skip=true clean install

$ cflint --help
-bash: cflint: command not found

Do I need to add cflint to the path?

NoViableAltException java.lang.NullPointerException

I'm getting multiple NoViableAltException java.lang.NullPointerException errors like the following when scanning a folder:

-------NoViableAltException(94@[])
java.lang.NullPointerException
        at org.antlr.runtime.tree.BaseTreeAdaptor.isNil(BaseTreeAdaptor.java:70)
        at org.antlr.runtime.tree.CommonTreeNodeStream.nextElement(CommonTreeNodeStream.java:91)
        at org.antlr.runtime.misc.LookaheadStream.fill(LookaheadStream.java:107)
        at org.antlr.runtime.misc.LookaheadStream.syncAhead(LookaheadStream.java:101)
        at org.antlr.runtime.misc.LookaheadStream.LT(LookaheadStream.java:122)
        at org.antlr.runtime.tree.CommonTreeNodeStream.LA(CommonTreeNodeStream.java:120)
        at cfml.parsing.cfscript.CFScriptTree.scriptBlock(CFScriptTree.java:249)
        at cfml.parsing.CFMLParser.parseScript(CFMLParser.java:329)
        at com.cflint.CFLint.process(CFLint.java:280)
        at com.cflint.CFLint.processStack(CFLint.java:197)
        at com.cflint.CFLint.process(CFLint.java:275)
        at com.cflint.CFLint.processStack(CFLint.java:197)
        at com.cflint.CFLint.process(CFLint.java:284)
        at com.cflint.CFLint.processStack(CFLint.java:197)
        at com.cflint.CFLint.process(CFLint.java:284)
        at com.cflint.CFLint.processStack(CFLint.java:197)
        at com.cflint.CFLint.process(CFLint.java:284)
        at com.cflint.CFLint.processStack(CFLint.java:197)
        at com.cflint.CFLint.process(CFLint.java:188)
        at com.cflint.CFLint.scan(CFLint.java:145)
        at com.cflint.CFLint.scan(CFLint.java:139)
        at com.cflint.CFLint.scan(CFLint.java:116)
        at com.cflint.main.CFLintMain.execute(CFLintMain.java:251)
        at com.cflint.main.CFLintMain.main(CFLintMain.java:164)

Argument appScope is not required and does not define a default value.

I'm running the latest CFLint built from the source of the master branch. Here is my code from my Application.cfc.

<cffunction name="onSessionEnd" returnType="void" output="false">
    <cfargument name="sessionScope" type="struct" required="true">
    <cfargument name="appScope" type="struct" required="false">
</cffunction>

ignore .cfm~ files

when you edit a file in vim, it creates a temporary 'save' file that takes the very same name as the file that you are editing but with a tilde (~) appended to the extension of the filename. CFLint currently analyses those files as well.

maven install should install the binaries in a usable way

Following mvn clean install I currently symlink /src/CFLint/target/appassembler/bin/cflint to somewhere in my path (/.local/bin). I also have to make the binary executable chmod a+x ~/src/CFLint/target/appassembler/bin/cflint. These steps (setting permissions, and installing the appassembler artifacts) should be part of the install.

Machine independent new lines

In the following file:
https://github.com/ryaneberly/CFLint/blob/master/src/main/java/com/cflint/TextOutput.java
I was looking to add machine independent new lines by replacing "\r\n" with one of the suggestions from this link: http://stackoverflow.com/questions/18549704/java-filewriter-create-a-new-line?lq=1

Not being a java developer, I'm unable to rebuild the project. I've added all the dependencies into eclipse, but when I try to run src/main/ant/build.xml by right clicking the file and running, I get an error message to provide Dfolder, which I try to do in the External Tools configuration, but I can't figure out where to add it.

Sorry if this is something simple. I'd love to be able to build this and help contribute to the project.

Use latest (antlr4) version of cfparser.

I tested against our large code base, and get the same flags, plus some new ones due to less parsing failures.

Once other contributors have given feedback. Release the upgraded version.

CFParser Dependencies Not Resolved

There has been an issue with deploying the combined cfparser files. I have requested hosting on Maven Central to satisfy this issue more easily. Until this is resolved, please install cfparser before installing CFLint.

download "github.com/cfparser/cfparser" then run "mvn clean install"
after a successful install, download "github.com/cflint/CFLint" then run "mvn clean install"

Hopefully this should be fixed in a few days and we can all be on our merry way.

Add severity level to each issue in stdout

Hi Ryan,
Sorry for not thinking about this before, would it be terribly difficult to add the severity level to the output of each instance of an issue rather than just once at the top in the stdout mode?

Excess Libraries

Deleted lib folder which contained cfml.dictionary and cfml.parsing. Please pull and test before closing.

compat issue with Local History package

linting a cfc, console shows:

Exception in thread Thread-14:
Traceback (most recent call last):
File "X/threading.py", line 639, in _bootstrap_inner
File "X/threading.py", line 596, in run
File "history in C:\Users\amiller.MRIOA2\AppData\Roaming\Sublime Text 3\Installed Packages\Local History.sublime-package", line 83, in process_history
File "history in C:\Users\amiller.MRIOA2\AppData\Roaming\Sublime Text 3\Installed Packages\Local History.sublime-package", line 83, in
File "X/genericpath.py", line 54, in getmtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: '2014-05-23_08.34.01.Submitted.cfc'

removing the cflint package resolves that issue.

Trying out the configfile from the command line and getting errors

Trying out the configfile from the command line and getting errors. Maybe I'm using it wrong though. Posting in case it's a bug or we just need some documentation on it.

java -jar CFLint-0.3.0-all.jar -folder=cfc -configfile=cflint

Exception in thread "main" java.lang.ClassCastException: com.cflint.config.CFLintPluginInfo cannot be cast to com.cflint.config.CFLintConfig
at com.cflint.main.CFLintMain.execute(CFLintMain.java:222)
at com.cflint.main.CFLintMain.main(CFLintMain.java:164)

inside cflint file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CFLint-Plugin>
<ruleImpl name="CFDumpChecker">
<message code="code">
<messageText>messageText</messageText>
<severity>WARNING</severity>
</message>
</ruleImpl>
</CFLint-Plugin>

Unable to Parse QueryExecute Functions

                var result = QueryExecute("
            SELECT info_card_id, document_num, revision_nm, title_nm
            FROM tdc_doc_infocard
            WHERE info_card_id = :sourceTemplateNum
            ORDER BY UPPER(document_num) ASC, revision_seq DESC
        ", { sourceTemplateNum = { value="#sourceTemplateNum#", cfsqltype="cf_sql_varchar" }});

Is reporting:

decompile: [ public function getSourceTemplates(required sourceTemplateNum) {, var result = QueryExecute(' , SELECT info_card_id, document_num, revision_nm, title_nm , FROM tdc_doc_infocard , WHERE info_card_id = :sourceTemplateNum , ORDER BY UPPER(document_num) ASC, revision_seq DESC , ', {sourceTemplateNum:{value:'#sourceTemplateNum#',cfsqltype:'cf_sql_varchar'}}); return result;, }] { var result = QueryExecute(' SELECT info_card_id, document_num, revision_nm, title_nm FROM tdc_doc_infocard WHERE info_card_id = :sourceTemplateNum ORDER BY UPPER(document_num) ASC, revision_seq DESC ', {sourceTemplateNum:{value:'#sourceTemplateNum#',cfsqltype:'cf_sql_varchar'}}); return result; }

Misc. Parsing Error?

Misc Violation in CFLint-result:

Error   



  In file \TaskGateway.cfc, line 57
  In c:\v11\server\webapps\ROOT\WEB-      INF\railo\components\railo\extension\gateway\TaskGateway.cfc
  At line : 57
  Expression: [@209,1518:1521='file',<88>,57:56]

Function being parsed:

  23:     public function start() {
  24: 
  25:         while ( variables.state == "stopping" )
  26:             sleep( 10 );
  27: 
  28:         variables.state = "running";
  29: 
  30:         log text="Event Gateway #variables.id# started" file=this.logfile;
  31: 
  32:         while ( variables.state == "running" ) {
  33: 
  34:             try {
  35: 
  36:                 this.PerformTask();
  37:             }
  38:             catch ( ex ) {
  39: 
  40:                 log text="Event Gateway #variables.id# error: #ex.message#" file=this.logfile type="error";
  41:             }
  42: 
  43:             // sleep( variables.interval );
  44:             
  45:             var ts = getTickCount();
  46:             
  47:             while( getTickCount() - ts < variables.interval ) {
  48: 
  49:                 sleep( 1000 );
  50: 
  51:                 if ( variables.state != "running" )
  52:                     break;
  53:             }
  54:         }
  55: 
  56:         variables.state = "stopped";
  57:         log text="Event Gateway #variables.id# stopped" file=this.logfile;
  58:     }

Docs for using linter via java

Less a bug and more a request for help. Given that I've got an instance of the linter, and I see there is a scan API:

linter = createObject("java","com.cflint.CFLint");
linter.scan(selection.path);

But it returns void. How do I get the results?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.