JavaScript
The JavaScript Analyzer scans your JavaScript/TypeScript code, and raises issues if best practices are not followed. It also detects issues that are specific to frameworks/libraries like React, Vue, Angular, AngularJS, Meteor and Ember.
The analyzer is backwards compatible with ESLint, and will respect the ESLint config files present in your project.
Configuration - .deepsource.toml
This section covers configuration specific to the javascript analyzer. Please make sure to read the general configuration guide first.
name
- Type: String
- Presence: mandatory
- Description: Shortcode of the analyzer.
- Example:
name = "javascript"
enabled
- Type: Boolean
- Presence: optional
- Description: Toggle whether this analyzer should be run.
- Example:
enabled = true
meta
- Type: Table
- Presence: optional
- Description: Any supported metadata to pass to the analyzer.
- Example:
[analyzers.meta]
plugins = ["angularjs"]
environment = ["nodejs", "jquery"]
dialect = "flow"
skip_doc_coverage = ["class-expression", "method-definition"]
plugins
- Type: Array
- Presence: optional
- Description: The JavaScript frameworks/libraries being used in the project. Currently, we support React, Vue, EmberJS, Meteor, Angular, and AngularJS.
- Available Values:
react,vue,ember,meteor,angularandangularjs - Default Value: None
- Example:
plugins = ["angularjs"]
Except angularjs, DeepSource automatically detects the aforementioned frameworks/libraries if their corresponding dependencies are present in the project's package.json file(s).
If your project uses angularjs, or if you are consuming any of the above frameworks/libraries via a CDN, or some other method, you need to add them here explicitly.
environment
-
Type: Array
-
Presence: optional
-
Description: The global variables related to the environments used that need to be predefined for the project.
-
Available Values:
nodejs,browser,jest,mocha,jasmine,jquery,mongo,cypress,vitestnodejs- Adds Node.js global variables and Node.js scopingbrowser- Adds Browser specific global variablesjest- Adds Jest global variablesmocha- Adds Mocha testing global variablesjasmine- Adds Jasmine testing global variables for version 1.3 and 2.0jquery- Adds jQuery global variablesmongo- Adds MongoDB global variablescypress- Adds Cypress global variablesvitest- Adds Vitest global variables
-
Default Values: ["browser"]
-
Example:
environment = ["nodejs", "jest"]
Except nodejs, DeepSource automatically detects the aforementioned libraries if their corresponding dependencies are present in the project's package.json file(s).
If your project uses nodejs, or if you are consuming any of the above libraries via a CDN, or some other method, you need to add them here explicitly.
module_system
-
Type: String
-
Presence: optional
-
Description: The type of modules used in the project.
-
Available Values:
commonjs,es-modulesandamdcommonjs- The CommonJS Module System. (require/exports)es-modules- ES Modules (import/export)amd- Asynchronous Module Definition (define/require)
-
Default Value: "es-modules"
-
Example:
module_system = "es-modules"
dialect
- Type: String
- Presence: optional
- Description: The dialect of JavaScript used in the project. Currently, we support TypeScript and Flow.
- Available Value:
typescriptandflow - Default Value: "typescript"
- Example:
dialect = "flow"
skip_doc_coverage
-
Type: Array
-
Presence: optional
-
Description: Specify which artifacts to skip when detecting documentation issues and calculating documentation coverage.
-
Available Values:
function-declaration,function-expression,arrow-function-expression,class-declaration,class-expressionandmethod-definitionfunction-declaration- Ignore function declarationsfunction-expression- Ignore function expressionsarrow-function-expression- Ignore arrow function expressionsclass-declaration- Ignore class declarationsclass-expression- Ignore class expressionsmethod-definition- Ignore method definitions
-
Default Value: []
-
Example:
skip_doc_coverage = ["class-expression", "method-definition"]
style_guide
-
Type: String
-
Presence: optional
-
Description: A style guide is a set of standards that outline how code should be written and organized. Setting this will ensure that you follow established conventions, and will also allow the analyzer to raise issues for any style guide violations.
-
Available Values:
airbnb,googleandstandardairbnb- Airbnb JavaScript Style Guidegoogle- Google JavaScript Style Guidestandard- Standard JavaScript Style Guide
-
Default Value: None
-
Example:
style_guide = "airbnb"
Sample config
Configuration without meta
version = 1
test_patterns = ["*/test/**"]
exclude_patterns = [
"public/**,",
"dist/**"
]
[[analyzers]]
name = "javascript"
enabled = true
Configuration with meta
version = 1
test_patterns = ["*/test/**"]
exclude_patterns = [
"public/**,",
"dist/**"
]
[[analyzers]]
name = "javascript"
enabled = true
[analyzers.meta]
plugins = ["angularjs"]
environment = [
"nodejs"
]
dialect = "flow"
skip_doc_coverage = ["class-expression", "method-definition"]
ESLint Rules & Plugins
The DeepSource JavaScript analyzer supports most of the ESLint core rules. Currently, the following ESLint plugins are supported as well:
- Node
- TypeScript
- React
- Vue
- Flow
- Ember
- Meteor
- Angular
- AngularJS
Custom plugins specific to your project, and other third party plugins are not supported. If a specific rule is explicitly disabled in your repo's ESLint config, DeepSource will respect that and not raise any issues that are similar to that rule.
Dependency Calculation
DeepSource uses the package.json file for calculating the count of third-party dependencies.
The package.json file format is supported by all major dependency managers like npm, pnpm, yarn and rush.