From commits-return-10574-apmail-roller-commits-archive=roller.apache.org@roller.apache.org Sun Nov 3 07:24:02 2019 Return-Path: X-Original-To: apmail-roller-commits-archive@www.apache.org Delivered-To: apmail-roller-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 76BB510317 for ; Sun, 3 Nov 2019 07:24:02 +0000 (UTC) Received: (qmail 72477 invoked by uid 500); 3 Nov 2019 07:24:01 -0000 Delivered-To: apmail-roller-commits-archive@roller.apache.org Received: (qmail 72441 invoked by uid 500); 3 Nov 2019 07:24:01 -0000 Mailing-List: contact commits-help@roller.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@roller.apache.org Delivered-To: mailing list commits@roller.apache.org Received: (qmail 72431 invoked by uid 99); 3 Nov 2019 07:24:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Nov 2019 07:24:01 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id CA5CFE0451 for ; Sun, 3 Nov 2019 07:24:00 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 0EA627804F8 for ; Sun, 3 Nov 2019 07:24:00 +0000 (UTC) Date: Sun, 3 Nov 2019 07:24:00 +0000 (UTC) From: "Aditya Sharma (Jira)" To: commits@roller.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (ROL-2157) Variables should be declared explicitly in Custom JS code MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Aditya Sharma created ROL-2157: ---------------------------------- Summary: Variables should be declared explicitly in Custom JS = code Key: ROL-2157 URL: https://issues.apache.org/jira/browse/ROL-2157 Project: Apache Roller Issue Type: Improvement Reporter: Aditya Sharma Assignee: Aditya Sharma Pattern is identified and reported at=C2=A0 sonacloud.io as Blocker JavaScript variable scope can be particularly difficult to understand and g= et right. The situation gets even worse when you consider the _accidental_ = creation of global variables, which is what happens when you declare a vari= able inside a function or the {{for}} clause of a for-loop without using th= e {{let}}, {{const}} or {{var}} keywords. {{let}} and {{const}} were introduced in ECMAScript 2015, and are now the p= referred keywords for variable declaration.=C2=A0 Noncompliant Code Example =C2=A0 {code:java} function f(){ i =3D 1; // Noncompliant; i is global for (j =3D 0; j < array.length; j++) { // Noncompliant; j is global now too // ... } } {code} =C2=A0 Compliant Solution =C2=A0 {code:java} function f(){ var i =3D 1; for (let j =3D 0; j < array.length; j++) { // ... } } {code} =C2=A0 -- This message was sent by Atlassian Jira (v8.3.4#803005)