Giter VIP home page Giter VIP logo

escomplex's Introduction

escomplex

Greenkeeper badge Build Status Known Vulnerabilities Dependencies Dev Dependencies

Software complexity analysis of JavaScript abstract syntax trees. The back-end for complexity-report.

Installation

The library is published on npm under the name escomplex. To install, you can add it to the dependencies in your package.json file or simply run:

npm i escomplex --save

Usage

You can use escomplex by including it as an Node.js module:

const escomplex = require('escomplex');

The module exports the analyse function.

analyse

The analyse function is used to convert the source code of one or more modules into one or more corresponding report objects containing metrics.

const result = escomplex.analyse(source, options);

Arguments

source

The first argument, source, must be either a string or an array of objects. If it is an array, each object should include a path property that is either a relative or full path to the equivalent module on disk and a code with the contents of the module. As well as identifying each of the result objects, the path property is also used during dependency analysis.

options

The third argument, options, is an optional object containing properties that modify some of the complexity calculations:

  • options.logicalor: Boolean indicating whether operator || should be considered a source of cyclomatic complexity, defaults to true.
  • options.switchcase: Boolean indicating whether switch statements should be considered a source of cyclomatic complexity, defaults to true.
  • options.forin: Boolean indicating whether for...in loops should be considered a source of cyclomatic complexity, defaults to false.
  • options.trycatch: Boolean indicating whether catch clauses should be considered a source of cyclomatic complexity, defaults to false.
  • options.newmi: Boolean indicating whether the maintainability index should be rebased on a scale from 0 to 100, defaults to false.
  • options.skipCalculation: only valid for when source is an array of files Boolean indicating if we should skip processing of certain values, such as the adjacency and visibility matrixes, core sizes, and average values loc, etc.
  • options.noCoreSize: Skips creating the visibility matrix and calculating the coreSize, which can be very expensive for large projects

Result Format

The analyze function returns a report of the following format, with some variation depending on the given options.

For a single module

If a single source string is passed in the source argument, the result will be a report object that looks like the following:

{
    maintainability: 171,
    dependencies: [],
    aggregate: {
        sloc: {
            logical: 0,
            physical: 0
        },
        params: 0,
        cyclomatic: 1,
        cyclomaticDensity: 1,
        halstead: {
            vocabulary: 0,
            difficulty: 0,
            volume: 0,
            effort: 0,
            bugs: 0,
            time: 0
        }
    },
    functions: [
        {
            name: '',
            line: 0,
            sloc: {
                logical: 0,
                physical: 0
            },
            params: 0,
            cyclomatic: 1,
            cyclomaticDensity: 1,
            halstead: {
                vocabulary: 0,
                difficulty: 0,
                volume: 0,
                effort: 0,
                bugs: 0,
                time: 0
            }
        },
        ...
    ]
}

The meaning of those values, briefly, is as follows (see metrics for more information on each one):

  • report.maintainability: The maintainability index for the module.
  • report.dependencies: The array of CommonJS/AMD dependencies for the module.
  • report.aggregate.sloc.physical: Physical lines of code for the module. Will be undefined if the syntax tree is not annotated with line number data.
  • report.aggregate.sloc.logical: Logical lines of code for the module.
  • report.aggregate.params: Parameter count for the module.
  • report.aggregate.cyclomatic: Cyclomatic complexity for the module.
  • report.aggregate.cyclomaticDensity: Cyclomatic complexity density for the module.
  • report.aggregate.halstead.vocabulary: Halstead vocabulary size for the module.
  • report.aggregate.halstead.difficulty: Halstead difficulty for the module.
  • report.aggregate.halstead.volume: Halstead volume for the module.
  • report.aggregate.halstead.effort: Halstead effort for the module.
  • report.aggregate.halstead.bugs: Halstead bugs for the module.
  • report.aggregate.halstead.time: Halstead time for the module.
  • report.functions[n].name: Function name.
  • report.functions[n].line: Line number that the function starts on. Will be undefined if the syntax tree is not annotated with line number data.
  • report.functions[n].sloc.physical: Physical lines of code for the function. Will be undefined if the syntax tree is not annotated with line number data.
  • report.functions[n].sloc.logical: Logical lines of code for the function.
  • report.functions[n].params: Parameter count for the function.
  • report.functions[n].cyclomatic: Cyclomatic complexity for the function.
  • report.functions[n].cyclomaticDensity: Cyclomatic complexity density for the function.
  • report.functions[n].halstead.vocabulary: Halstead vocabulary size for the function.
  • report.functions[n].halstead.difficulty: Halstead difficulty for the function.
  • report.functions[n].halstead.volume: Halstead volume for the function.
  • report.functions[n].halstead.effort: Halstead effort for the function.
  • report.functions[n].halstead.bugs: Halstead bugs for the function.
  • report.functions[n].halstead.time: Halstead time for the function.

For multiple modules

If an array of sources is passed in the source argument, the result will be an object that looks like the following:

{
    reports: [
        ...
    ],
    adjacencyMatrix: [
        [ 0 ]
    ],
    firstOrderDensity: 0,
    visibilityMatrix: [
        [ 0 ]
    ],
    changeCost: 100,
    coreSize: 100,
    loc: 0,
    cyclomatic: 1,
    effort: 0,
    params: 0,
    maintainability: 171
}

Those properties are defined as follows:

  • result.reports: An array of report objects, each one in the same format described above but with an extra property path that matches the path property from its corresponding syntax tree. This path property is required because the reports array gets sorted during dependency analysis.
  • result.adjacencyMatrix: The adjacency design structure matrix (DSM) for the project. This is a two-dimensional array, each dimension with the same order and length as the reports array. Each row and column represents its equivalent indexed module from the reports array, with values along the horizontal being 1 when that module directly depends on another and values along the vertical being 1 when that module is directly depended on by another. All other values are 0.
  • result.firstOrderDensity: The first-order density for the project.
  • result.visibilityMatrix: The visibility DSM for the project. Like the adjacency matrix, but expanded to incorporate indirect dependencies. Will be missing if noCoreSize is passed as an option.
  • result.changeCost: The change cost for the project. Will be missing if noCoreSize is passed as an option.
  • result.coreSize: The core size for the project.
  • result.loc: The average per-function count of logical lines of code.
  • result.cyclomatic: The average per-function cyclomatic complexity.
  • result.effort: The average per-function Halstead effort.
  • result.params: The average per-function parameter count.
  • result.maintainability: The average per-module maintainability index.

Refer to a more in-depth description of the metrics used for more details.

Related projects

  • plato: JavaScript source code visualization, static analysis, and complexity tool.
  • jsc: JavaScript source code complexity tool.
  • bob: Minimalist-omakase build tool for node.js projects.
  • cardio: A web application health tool.
  • grunt-complexity: A JavaScript complexity analysis grunt task.
  • atom-linter-escomplex: Lining code complexity in Atom editor.
  • brackets-crjs: Brackets extension.
  • jscomplexity: JS cyclomatic complexity report generator.
  • karma-complexity-processor: A preprocessor for karma runner to give some metrics about code complexity.
  • crlint: JS linter based on complexity report results.

Contributing

All changes should be submitted in the form of a pull request. Please refer to the contribution guidelines before submitting a pull request.

Source code is in /src. Unit tests are in /test. You can run the tests with npm test. You can run the linter with npm run lint. Make sure you've installed all the dependencies with npm install first.

License

MIT

escomplex's People

Contributors

adam-moss avatar addisonj avatar antono avatar apergy avatar avandeursen avatar ehmicky avatar geek avatar gobie avatar greenkeeper[bot] avatar greenkeeperio-bot avatar iankronquist avatar jared-stilwell avatar juzerali avatar lonekorean avatar maxdow avatar mcandre avatar nilos avatar philbooth avatar rowanmanning avatar zzo 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

escomplex's Issues

Error: Cannot find module 'esprima'

Into index.js is used esprima (line 5):

var esprima = require('esprima');

But this package is installed only as devDependencies on package.json:

"devDependencies": { "chai": "^3.4.1", "eslint": "^2.2.0", "esprima": "^2.7.1", "mocha": "^2.3.4", "mockery": "1.4.x", "sinon": "^1.16.1", "spooks": "0.5.x" },

As a result, the escomplex package cannot be use with a simple:

npm install escompex

Beware of the Maintainability Index

Thanks for maintaining a helpful JavaScript metrics project.

One of the metrics you offer, the "Maintainability Index", however, is an outdated metric that has some serious problems. There are several research papers essentially drawing this conclusion. I have summarized these papers in a blog post Think Twice Before Using the “Maintainability Index”.

Maybe it would be useful to add a pointer to this blog post in your Links to Research section in your README? If you agree, let me know and I can create a pull request.

(Some of my students are happily using escomplex, but then unfortunately also draw unjustified conclusions based on the "Maintainability Index". A warning might help.)

Provide an alias for the "analyse" function in index.js

In order to avoid confusion among American English-speakers, the top-level API of escomplex should include a function analyze that is an alias to the analyse function.

The README.md also needs to be cleaned up a bit. It contains typos where analyze should really be analyse instead. The references in the README.md and other documentation should still be analyse going forward. This alias is simply a safety mechanism so that consumers can still "misspell" the function name and have it just work.

Cyclomatic returns 1 for a file containing 1 if and 1 if-else inside a for loop

image
I have a file with these lines of code:

const smArr = [5, 3, 2, 35, 2];
const bigArr = [5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2, 5, 3, 2, 35, 2];

//O(log n)
const sort = arr => {
    if (arr.length < 2) return arr;
  
    let pivot = arr[0];
    let left = [];
    let right = [];
  
    for (let i = 1, total = arr.length; i < total; i++) {
      if (arr[i] < pivot) left.push(arr[i]);
      else right.push(arr[i]);
    };
    return [
      ...sort(left),
      pivot,
      ...sort(right)
    ];
  };

sort(smArr); // 0 Milliseconds
sort(bigArr); // 1 Millisecond

It contains 1 if and 1 if-else inside a for loop. However, cyclomatic returns 1. Is it correct?

escomplex does not support ES6 class contents properly

See attached complexity report and test inputs. It looks like complexity report (and likely the underlying escomplex) doesn't see code within ES6 classes. The sample (es6classtest3.js) has a class containing one function, and that doesn't show up in the complexity report (cr.txt). A control sample without a class (es6classtest2.js) is analyzed correctly.

I tested with complexity-report 2.0.0-alpha - since the underlying issue is in escomplex, I'm reporting it here as well as suggested by @jared-stilwell - his comments are below:

There are essentially two limiting factors here. The first is Esprima's support for parsing ES6 into an AST that complies with the ESTree spec. While Esprima has already implemented support for parsing ES6 classes, the escomplex module does not yet have support for processing the resulting AST nodes.

In short, once support for ES6 classes makes it into escomplex, then your classes should show up in the complexity report. Please open an issue on the escomplex project to support ES6 classes and I'll prioritize this accordingly.

`nilHalsteadMetrics()` doesn't need to be a function in module.js

The nilHalsteadMetrics() method is only called on line 289 module.js. This logic can be moved inline.

e.g.

...
function calculateHalsteadMetrics (data) {
  data.length = data.operators.total + data.operands.total;
  if (data.length === 0) {
    data.vocabulary = 0;
    data.difficulty = 0;
    data.volume = 0;
    data.effort = 0;
    data.time = 0;
    data.bugs = 0;
  } else {
...

&& missing in cyclomatic complexity measure.

McCabe's cyclomatic complexity is defined as V(p) = e - n + 2p. For p = 1, it should be calculated as follows: V(p) = π + 1, where π is the number of predicates in the program. It seems like you are missing the predicates made of the && - operator?

Update of dependency spooks causes test failures

Updating dependency spooks from 0.5.x to 2.0.x results in some test failures:

635 passing (819ms)
61 pending
6 failing

  1. index: require: array source: core.analyse was given correct asts:
    AssertionError: expected undefined to equal 'esprima.parse result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/index.js:143:24)

  2. index: require: array source: correct result was returned:
    AssertionError: expected undefined to equal 'core.analyse result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/index.js:161:24)

  3. index: require: string source: core.analyse was given correct ast:
    AssertionError: expected undefined to equal 'esprima.parse result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/index.js:231:24)

  4. index: require: string source: correct result was returned:
    AssertionError: expected undefined to equal 'core.analyse result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/index.js:243:24)

  5. index: require: string arguments: operators was correct:
    AssertionError: expected undefined to equal 'operators result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/traits.js:127:24)

  6. index: require: string arguments: operands was correct:
    AssertionError: expected undefined to equal 'operands result'
    at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:178:32)
    at Context. (test/traits.js:131:24)

Improve the contribution documentation

The hoodie contributing docs are second to none. Steal as much as you can from them, while respecting the project license.

Additional goals:

  • Establish a code of conduct for all communication within the project.
  • Be clear about what contributors should expect. Talk about the process from contribution through review and acceptance.
  • Be explicit about what is and is not acceptable in terms of code quality, coverage, or style.
  • Offer tips for making the submissions easier to accept.

`JSON.stringify(ast)` after `parseProject` causes overflow error on large project even if `debug` is a noop

debug(JSON.stringify(ast, null, 2))

  escomplex Custom parse function +0ms
  escomplex Parsed AST:  +7s
/__CENSORED__/node_modules/escomplex/src/index.js:36
  debug(JSON.stringify(ast, null, 2))
             ^

RangeError: Invalid string length
    at join (native)
    at Object.stringify (native)
    at Object.module.exports.analyse (/__CENSORED__/node_modules/escomplex/src/index.js:36:14)
    at nextFile (/__CENSORED__/bin/development/complexity-summary.js:58:44)
    at onFileProcessed (/__CENSORED__/bin/development/complexity-summary.js:80:7)
    at onFileRead (/__CENSORED__/bin/development/complexity-summary.js:49:5)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

JSON.stringify(ast, null, 2) is executed unconditionally causing the whole analysis to fail even if I don't enable the debug output.

Update authorship

Update author references in:

  • package.json
  • CONTRIBUTING.md
  • AUTHORS
  • COPYING

CallExpression throwing error

Reposted from https://github.com/jared-stilwell/escomplex-ast-moz/issues/88

Whenever I run the following code:

const file = fs.readFileSync(filePath);
const ast = esprima.parse(file, {range: true, comment: true});
const escomplexResult = escomplex.analyse(ast, escomplexWalker);

an the code has CallExpressions I get the following error: http://imgur.com/xTcEDzN

This code was previously working for me

This fixed the issue :

const ast = esprima.parse(file, {loc: true, range: true, comment: true});

The indication that the walker needs the loc option should be indicated.

An in-range update of mocha is breaking the build 🚨

Version 3.4.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v3.4.0

Mocha is now moving to a quicker release schedule: when non-breaking changes are merged, a release should happen that week.

This week's highlights:

  • allowUncaught added to commandline as --allow-uncaught (and bugfixed)
  • warning-related Node flags

🎉 Enhancements

🐛 Fixes

🔩 Other

Commits

The new version differs by 9 commits0.

  • 7554b31 Add Changelog for v3.4.0
  • 9f7f7ed Add --trace-warnings flag
  • 92561c8 Add --no-warnings flag
  • ceee976 lint test/integration/fixtures/simple-reporter.js
  • dcfc094 Revert "use semistandard directly"
  • 93392dd no special case for macOS running Karma locally
  • 4d1d91d --allow-uncaught cli option
  • fb1e083 fix allowUncaught in browser
  • 4ed3fc5 Add license report and scan status

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Update the top-level API to be more explicit

Currently, the escomplex module exports a single function: analyse.

The behavior of the the analyse function changes implicitly based on the first argument passed to it. When it is passed a string code source, analysis is performed on the single source module and a single report object is returned.

If an array is passed as the first argument, we assume each item in the array is an object with the string properties path and code. In this case a report object or aggregate metrics is returned. The aggregate report object also contains the the reports property with a collection of the individual reports indexed parallel to the collection of sources originally passed as the first argument.

Cramming both the module case (i.e. a single code source) and the project case (i.e. a collection of sources with path information) into the same function overly complicates the internals. It is a more direct expression to draw a clear difference between these two use cases in the top-level API, while still maintaining the original contract of the analyse function for convenience and backward compatibility.

The end result is to have three functions exported from the escomplex module:

  • analyse
  • analyseModule
  • analyseProject

The analyse function would then simply delegate to either analyseModule or analyseProject based on the shape of the first argument, passing the options object through.

Greets and a few comments.

@jared-stilwell (and contributors) thanks for taking on maintaining escomplex. I'd certainly like to integrate it with ESDoc as a plugin in addition to using D3 for interactive graphs of the data generated. I've already done basic integration tests and here are my thoughts (hopefully this isn't a bit presumptuous).

I'd just like to know your intentions (I've read your blog posts) for escomplex and if you can see yourself and others working on it to get it up to production standards? I'd be glad to help out in this regard or simply fork what you have as the skeleton framework is here. I'd prefer to collaborate / contribute if possible. The velocity is quite slow and unclear if there are intentions to make a production ready release on the horizon.

From one of your blog posts...

We'll continue using Esprima and set a goal to support any parser that complies with the EStree specification.

As it stands currently Esprima is a "surface" dependency (though not added in the package.json!) for escomplex I do recommend splitting off all of the AST processing to escomplex-core. And leave escomplex to just the index.js. Esprima is only used in index.js to generate the AST and is an unnecessary dependency for integration where parsing is already handled.

The reason being is that Espree is also a common ESTree based parser and is the one used in ESDoc and AST is already generated in ESDoc which can easily be sent to the core functionality of escomplex.

Here is the simple test integration I've made which outputs escomplex reports for every file processed by ESDoc (this is ES6 code too as espree is configured for ES6):
esdoc-plugin-escomplex/src/analyse.js
esdoc-plugin-escomplex/src/plugin.js

The main reason ES6 code is not parsed by escomplex right now is because incomplete options are being fed to esprima. If esprima is anything like espree too you have to vary the options depending on code being processed.

Of course the AST import directives are not being processed by escomplex and such. I can certainly help add the ES6 AST processing as I've been working a lot with ES6 AST recently.

Other small comments if you move forward I suggest creating a Github organization for escomplex and related repos. It makes it a lot easier to organize collaborators.

If there is a chance that you don't see yourself and others getting a production version together that supports ES6 anytime soon let me know. I'd be glad to setup a Github organization and just get it done as a production version shouldn't take more than 3 days effort if that. Again a bit presumptuous on my part.

Publish latest version to npm

The version is on npm is 2.0.0.alpha, which is the same as current one on GitHub.

However this is misleading, because the version published on npm is from this commit, which is 18 months and about 50 commits old.

Possible suggestions:

  • upgrading version to 2.0.0
  • publishing to npm
  • introduce more frequent version upgrading and publishing

Update README.md to match top-level API

The top-level interface for this package now includes three methods:

  • analyse
  • analyseModule
  • analyseProject

Update the README.md to document each of these, and provide docs/examples of using a custom parser.

Allow parsing to be overridden via the top-level module API

As an initial step toward providing support for modern language features, the public API for the module needs to be updated. A third argument should be introduced to the analyse function that can either be an object or a function.

If the third argument is provided as an object, it should be treated as an override to the options passed to the default parser (esprima at the time of writing). Nodes in the resulting abstract syntax tree (AST) are required to be annotated with location in order for the reporting to be accurate. Consequently, the loc option should be hard-set to true.

If the third argument is provided as a function, it should be treated as a callback which accepts source code as a string and returns an AST.

Refactor all the syntax definitions into modules by language specification

Having all the syntax definitions reside in individual modules definitely works, but it becomes cumbersome pretty quickly to hop between files when making significant changes.

Instead, refactor the syntax definitions for the ES5 spec and below into a single module. Likewise, factor any ES6 language features into a single module. This will make the support levels for the ES6+ spec much more explicit in the file structure and should ease the process toward full compatibility with future language specs.

An in-range update of acorn is breaking the build 🚨

Version 5.6.1 of acorn was just published.

Branch Build failing 🚨
Dependency acorn
Current Version 5.6.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

acorn is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 2 commits.

  • 690cfc7 Mark version 5.6.1
  • e50701d Allow null to be passed as base visitor to walk.recursive

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Proof of concept ES6+ / acorn / espree / esprima / babylon support complete

Greets @jared-stilwell et al,

I just finished a significant refactor of escomplex that fully supports ES6 along with acorn, espree, esprima generated AST. (edit: and ES7 / all babylon features!)

Edit: you can read the rest of this issue / thread and learn that my refactor was not accepted by @jared-stilwell for reasons, however I now have a fully published next generation version of escomplex available here:
https://www.npmjs.com/package/typhonjs-escomplex
https://www.npmjs.com/package/typhonjs-escomplex-module
https://www.npmjs.com/package/typhonjs-escomplex-project

This new refactor is modular and uses a plugin architecture for easy extension and will see several feature enhancements in short order. Please review all modules available at the typhonjs-node-escomplex organization. Cheers...


I split off all AST processing to escomplex-core and removed all external dependencies including node so escomplex-core can be used anywhere including the browser.

escomplex has the same API, but I switched things to espree as it's a way better parser than esprima and conformant to the ESTree spec which esprima is not.

Don't fret though as I resolved all of the issues in supporting acorn / espree / esprima and escomplex-core runs all test suites against these 3 parsers. I also added a thorough test suite for ES6 which is almost twice as large as the core module test suite.

For now you can use the following in package.json to test things out:

  "dependencies": {
    "escomplex": "git+https://[email protected]/typhonjs-node-escomplex/escomplex.git",
  },

or just for the core AST processing:

  "dependencies": {
    "escomplex-core": "git+https://[email protected]/typhonjs-node-escomplex/escomplex-core.git",
  },

@jared-stilwell I'd be glad to do a PR once you get to check things out.

Use espree as the default parser

As mentioned in #30, Espree constitutes a better default parser that makes Esprima compatibility an explicit design goal. Replace Esprima with Espree as the default parser in index.js

Call for maintainers

This repository is now unmaintained. If you are interested in assuming maintainership, please comment on this issue or email me directly.

support for other parsers

Hi Jared,
I'm building a tool to capture and analyse source code complexity and I've been happily using escomplex as far as javascript is concerned. Unfortunately some of the projects I've been testing my tool against have started adopting es6 and React with JSX, and that obviously is creating some problems.

I'd like to describe the two main problems I've been trying to work around before you agree to actually open a new issue for escomplex.

The first problem I have is that some of the projects are migrating from old legacy javascript to the new ES6, where that their frontend code is a mix of old and new javascript code. That means that I need to be able to parse it either with sourceType = 'script' or sourceType = 'module'. Unfortunately I don't see a way to pass specific esprima options to the escomplex.analyse function, so I resorted to bypass its natural facade by directly parsing the files with esprima and then invoking the analyse function in the escomplex/src/core module. I don't think this is a long term viable option as you may want to change your core module interface in the future.

The second problem I have is supporting non standard javascript features, like JSX in React for example.
I read in your post "The Next Version of ESComplex" that you're planning to support any parser that complies with the EStree specification, and I'm asking you when you think that may happen. I'm happy to offer help if you need it. At the moment again I resolved my problem by parsing the files with acorn, that has a plugin for JSX and produces a valid AST, and then again analysing the tree with escomplex core, but, as I said earlier, that feels more like a temporary workaround.

Thanks

Update the CHANGELOG.md

There are a number of issues and PRs that have been landed to the master branch, but haven't been released. Update the list of unreleased changes to represent all closed issues for the 2.0.0 milestone.

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.