Using ESLint

Install and Verify Node.js/NPM installation

Download Node.js from:: Node.js Download Location

Verify Nodes.js Installation

 

D:\Users\helmut>dir d:"\program files"\nodejs
 Verzeichnis von d:\program files\nodejs
08.12.2017  15:12        23.073.432 node.exe
22.12.2016  18:01               702 nodevars.bat
06.11.2017  20:33             8.997 node_etw_provider.man
27.12.2017  11:41                   node_modules
22.12.2016  18:01             4.974 node_perfctr_provider.man
16.11.2016  19:45               867 npm
16.11.2016  19:45               483 npm.cmd
08.12.2017  11:07               867 npx
08.12.2017  11:07               483 npx.cmd
               8 Datei(en),     23.090.805 Bytes
               3 Verzeichnis(se), 109.109.018.624 Bytes frei

D:\Users\helmut> npm -v
5.5.1

D:\Users\helmut> node -v
v8.9.3

Setup and Init ESLint

D:\Users\helmut> npm install -g eslint
D:\Users\helmut\AppData\Roaming\npm\eslint -> D:\Users\helmut\AppData\Roaming\npm\node_modules\eslint\bin\eslint.js
+ eslint@4.14.0
added 138 packages in 25.827s

D:\>   cd D:\xampp\htdocs\pv\SVGButton\public_html
D:\xampp\htdocs\pv\SVGButton\public_html>  eslint --init
? How would you like to configure ESLint? Inspect your JavaScript file(s)
? Which file(s), path(s), or glob(s) should be examined? *.js
? What format do you want your config file to be in? JavaScript
? Are you using ECMAScript 6 features? No
? Where will your code run? Browser
? Do you use CommonJS? No
? Do you use JSX? No
Determining Config: 100% [==============================] 0.4s elapsed, eta 0.0s

Enabled 222 out of 257 rules based on 1 file.
Successfully created .eslintrc.js file in D:\xampp\htdocs\pv\SVGButton\public_html

D:\xampp\htdocs\pv\SVGButton\public_html>dir
 Verzeichnis von D:\xampp\htdocs\pv\SVGButton\public_html

27.12.2017  12:10             8.432  .eslintrc.js
27.12.2017  10:47             3.363 button.js
26.12.2017  14:19             1.077 index.html
               3 Datei(en),         12.872 Bytes
               2 Verzeichnis(se), 108.942.053.376 Bytes frei

Running ESLint and fixing Potential Javascript Problems

D:\xampp\htdocs\pv\SVGButton\public_html>  eslint button.js
D:\xampp\htdocs\pv\SVGButton\public_html\button.js
   2:10  error  'loadSVGButton' is defined but never used    no-unused-vars
   6:2   error  Unexpected console statement                 no-console
   8:9   error  Unexpected console statement               no-console
  10:13  error  Unexpected console statement               no-console
  20:21  error  Unreachable code                             no-unreachable
  27:2   error  Unexpected console statement               no-console
  53:17  error  Unexpected console statement               no-console
.. 
---> 14 problems (14 errors, 0 warnings)

Fix 1: Fix console.log errors by adding "no-console": 0 to .eslintrc.js file 
    "rules": {
  	"no-console": 0,                       
        "accessor-pairs": "error",

Fix 2 : Fix defined but never used Error by using exported Flag 
D:\xampp\htdocs\pv\SVGButton\public_html\button.js
   2:10  error  'loadSVGButton' is defined but never used  no-unused-vars
  20:21  error  Unreachable code                           no-unreachable
---> 2 problems (2 errors, 0 warnings)    
-->Add to button.js 
/* exported loadSVGButton */      
function loadSVGButton() {

Fix 3: Fix  Unreachable code  Error by removing unecassary code line
D:\xampp\htdocs\pv\SVGButton\public_html\button.js
  20:21  error  Unreachable code  no-unreachable
--->  1 problem (1 error, 0 warnings)    

In button.js remove break command
19                default:
20                    throw "Invalid ButtonName: " + button.name;
21                    break;    

D:\xampp\htdocs\pv\SVGButton\public_html>eslint button.js
 --> No Errors/Warning