File .deepsource.toml
not found in the default branch of the repository root. Please refer to the docs.
let
or const
instead of var
JS-0239 84 );
85
86 const runBacktest = () => {
87 var singlesubscription: Substitution[]; 88 if (currentPlan && replacementPlan) {
89 submitSubstitution();
90 } else if (substitutions.length === 0) {
284
285 var valid_granularities: string[] = [];
286 if (currentMetric) {
287 for (var i = 0; i < all_proration_granularity.length; i++) {288 if (currentMetric.granularity === all_proration_granularity[i]) {
289 valid_granularities.push(all_proration_granularity[i]);
290 break;
282 (metric) => metric.billable_metric_name === form.getFieldValue("metric")
283 );
284
285 var valid_granularities: string[] = [];286 if (currentMetric) {
287 for (var i = 0; i < all_proration_granularity.length; i++) {
288 if (currentMetric.granularity === all_proration_granularity[i]) {
36
37const validateTiers = (tiers: Tier[]) => {
38 var currentStart = 0;
39 var currentEnd: number | undefined; 40 const arr2: boolean[] = tiers.map((tier, index) => {
41 if (index === 0) {
42 if (tier.range_end !== undefined && tier.range_start >= tier.range_end) {
35type ColumnTypes = Exclude<EditableTableProps["columns"], undefined>;
36
37const validateTiers = (tiers: Tier[]) => {
38 var currentStart = 0; 39 var currentEnd: number | undefined;
40 const arr2: boolean[] = tiers.map((tier, index) => {
41 if (index === 0) {
It is recommended to use let
or const
over var
.
This will help prevent re-declaration of variables that are in the global scope when using var
.
ES6 allows programmers to create variables with block scope instead of function scope using the let
and const
keywords.
Block scope is common in many other programming languages and helps programmers avoid mistakes such as this one:
var count = people.length;
var enoughFood = count > sandwiches.length;
if (enoughFood) {
var count = sandwiches.length; // accidentally overriding the count variable
console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}
// our count variable is no longer accurate
console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");
Block scoped variables shadow outer declarations instead of writing to them.
NOTE: There are certain edge cases where users might want to consider var. Consider this example:
var lib = lib || { run: () => {} }
Here, lib
might be a library that is exposed to an HTML file using a <script>
tag.
The var
keyword helps avoid re-writing lib
if it has already been declared via an injected script that was executed before this one.
Ideally, you should let bundlers worry about cases like this.
But if you want to use var
anyway, consider using a skipcq comment, or disabling the issue altogether.
var x = "y";
var CONFIG = {};
let x = "y";
const CONFIG = {};