Skip to content

DLint Developer Guide

Liang Gong edited this page Apr 23, 2015 · 2 revisions

Adding New Analyses

To add a new analysis:

  1. Add a .js file that implements the analysis to src/js/analyses/dlint. At the end of the execution, each analysis passes DLintWarnings to the DLint object (see existing analyses).
  2. Add the analysis to src/js/analyses/dlint/analyses.txt.
  3. Add tests for the analysis (see below).

Note: DLint framework currently adopts analysis2 API in Jalangi (not Jalangi2). It is primarily because Jalangi2 was not released when DLint was developed. We plan to migrate to Jalangi2 later.

Testing

Each analysis should have two kinds of tests:

  • Example programs that should trigger a warning. For node.js tests, add such programs to tests/dlint and name the file so that it starts with buggy_TheAnalysisName, For browser tests, add such programs to tests/html/dlint in a directory that starts with buggy_TheAnalysisName.
  • Example programs that should not trigger a warning. For node.js tests, add such programs to tests/dlint and name the file so that it starts with okay_TheAnalysisName. For browser tests, add such programs to tests/html/dlint in a directory that starts with okay_TheAnalysisName.

To run all node.js tests (verbose and debug are optional):

node tests/dlint/runAllTests.js [ verbose | debug ]

To run all browser tests (requires the setup described above):

node tests/dlint/runAllBrowserTests.js

To run a DLint warning and JSHint warning test:

  1. First make sure that a web server is started:
python -m SimpleHTTPServer
  1. Run the following command on another terminal:
export PATH="`pwd`/scripts/path_unix":$PATH
./scripts/dlint_lintTest.sh

It will first run Dlint on those webpages, then dump javascript files and warnings on the disk, finally, it will check if the number of those warnings and their types are correct.

How to Configure DLint Checkers?

The current version of DLint consists of around 30 checkers. But you can choose which checker to use when analyzing a web page. To add/remove a checker, add/remove the checker's file name in src/js/analyses/dlint/analyses.txt.

Note: Do not put any analysis before DLintPre.js or after DLintPost.js. If analysis A depends on analysis B, A should be listed after B in the configuration file.

A configuration of src/js/analyses/dlint/analyses.txt (including all the analyses):

DLintPre.js
utils/Utils.js
utils/document.js
utils/RuntimeDB.js
utils/levenshtein.js
CheckNaN.js
ConcatUndefinedToString.js
NonObjectPrototype.js
SetFieldOfPrimitive.js
OverFlowUnderFlow.js
StyleMisuse.js
ToStringGivesNonString.js
UndefinedOffset.js
NoEffectOperation.js
AddEnumerablePropertyToObject.js
ConstructWrappedPrimitive2.js
FunctionToString.js
ShadowProtoProperty.js
NonNumericArrayProperty.js
OverwrittenPrototype.js
DelayedCodeString.js
GlobalThis.js
CompareFunctionWithPrimitives.js
InconsistentConstructor.js
FunctionCalledWithMoreArguments.js
IllegalUseOfArgumentsVariable.js
ForInArray.js
DoubleEvaluation.js
InconsistentNewCallPrefix.js
UncountableSpaceInRegexp.js
EmptyClassInRegexp.js
UseArrObjConstrWithoutArg.js
MissRadixArgInParseNum.js
FloatNumberEqualityComparison.js
jsBuiltinFunctionChecker/DocumentFunctionsMisuse.js
jsBuiltinFunctionChecker/StringFunctionsMisuse.js
jsBuiltinFunctionChecker/RegExpFunctionsMisuse.js
jsBuiltinFunctionChecker/NumberFunctionsMisuse.js
jsBuiltinFunctionChecker/ObjectFunctionsMisuse.js
jsBuiltinFunctionChecker/GlobalFunctionsMisuse.js
jsBuiltinFunctionChecker/ArrayFunctionsMisuse.js
jsBuiltinFunctionChecker/DateFunctionsMisuse.js
ExeStat.js
Timer.js
DLintPost.js