Add and apply eslint's "prefer-const" rule
authorFrank Bessou <frank.bessou@logilab.fr>
Tue, 18 Apr 2017 14:47:44 +0200
changeset 125 abb84605bad5
parent 124 11d6f7145eb7
child 126 ea6ec8069edd
Add and apply eslint's "prefer-const" rule
.eslintrc.yml
src/components/Form.js
src/index.js
src/utils.js
test/index.js
--- a/.eslintrc.yml	Tue Apr 18 14:10:35 2017 +0200
+++ b/.eslintrc.yml	Tue Apr 18 14:47:44 2017 +0200
@@ -35,6 +35,7 @@
   no-use-before-define: [2, "nofunc"]
   object-curly-spacing: ["error", "never"]
   object-shorthand: off
+  prefer-const: "error"
   quotes: [0]
   react/jsx-indent-props: [2, 4]
   react/no-multi-comp: off
--- a/src/components/Form.js	Tue Apr 18 14:10:35 2017 +0200
+++ b/src/components/Form.js	Tue Apr 18 14:47:44 2017 +0200
@@ -21,7 +21,7 @@
             }
         }
 
-        for (let i in obj) {
+        for (const i in obj) {
             const type = typeof obj[i];
             if (type === 'object' && obj[i] !== null) {
                 this.adaptRecursively(obj[i]);
@@ -33,7 +33,7 @@
     getEnumFromOneOf(schema) {
         const enumValues = [];
         const enumNames = [];
-        for (let i in schema.oneOf) {
+        for (const i in schema.oneOf) {
             const constant = this.schemaToConstant(schema.oneOf[i], i);
             enumValues.push(constant.value);
             enumNames.push(constant.name);
--- a/src/index.js	Tue Apr 18 14:10:35 2017 +0200
+++ b/src/index.js	Tue Apr 18 14:47:44 2017 +0200
@@ -9,7 +9,7 @@
 
 import "script-loader!jsonary/super-bundle/jsonary-super-bundle.js"
 
-let appElement= document.getElementById('app');
+const appElement= document.getElementById('app');
 
 render((
     <Router history={browserHistory}>
--- a/src/utils.js	Tue Apr 18 14:10:35 2017 +0200
+++ b/src/utils.js	Tue Apr 18 14:47:44 2017 +0200
@@ -58,7 +58,7 @@
             return property.defined() && property.value() !== null
         });
 
-        for (let property of filteredProperties) {
+        for (const property of filteredProperties) {
             const propertyValue = buildFormData(property);
             formData[property.parentKey()] = propertyValue;
         }
--- a/test/index.js	Tue Apr 18 14:10:35 2017 +0200
+++ b/test/index.js	Tue Apr 18 14:47:44 2017 +0200
@@ -505,7 +505,7 @@
     });
 
     describe('getEntity', () => {
-        let api = new Api(baseUrl);
+        const api = new Api(baseUrl);
 
         const etype = 'foo';
         const eid = 123;
@@ -601,7 +601,7 @@
                 schema.d.e[1],
             ];
 
-            for (let args of expectedArgs) {
+            for (const args of expectedArgs) {
                 assert.calledWith(adapterFactory.adaptRecursively, args);
             }