From b8a431aedcdf9224ab146ef7afa153a544fab4fd Mon Sep 17 00:00:00 2001 From: samreid Date: Wed, 12 Dec 2018 08:46:01 -0700 Subject: [PATCH] Prevent for...of with a lint rule, and disable rule for non-sim cases, see https://github.com/phetsims/tasks/issues/972 --- eslint/.eslintrc | 586 ++++++++++++++++--------------- js/grunt/Gruntfile.js | 2 +- js/grunt/buildRunnable.js | 4 +- js/grunt/commitsSince.js | 2 +- js/grunt/getDependencies.js | 2 +- js/grunt/reportThirdParty.js | 2 +- js/grunt/updateCopyrightDates.js | 2 +- test/chainsBuildTest.js | 2 +- 8 files changed, 305 insertions(+), 297 deletions(-) diff --git a/eslint/.eslintrc b/eslint/.eslintrc index 20df00fad..5ea279333 100644 --- a/eslint/.eslintrc +++ b/eslint/.eslintrc @@ -1,290 +1,298 @@ -// Copyright 2002-2015 University of Colorado Boulder -// @author Sam Reid -// Note: IDEA wants to shrink all the line breaks in the file, so I'm using // to simulate line breakes where desired -{ - // Use all of the default rules from eslint, unless overriden below. - "extends": "eslint:recommended", - // The new rules, overrides, etc. - "rules": { - // - // Permit console.log statements (we have a lot of them) - // TODO: Find a way to make sure no console.log statements make it to production. Can use the no-console rule - // but we want to be able to use console.log during development. - "no-console": 0, - // - // specify whether backticks, double or single quotes should be used (fixable) - "quotes": [ - 2, - "single" - ], - // No dangling commas, see https://github.com/phetsims/tasks/issues/940 - "comma-dangle": 2, - // - // require or disallow use of semicolons instead of ASI (fixable) - "semi": [ - 2, - "always" - ], - "bad-text": 2, - // - // Custom rule for checking the copyright. - "copyright": 2, - // - // Custom rule for checking TODOs have issues - "todo-should-have-issue": 2, - // - // Custom rule for ensuring that images and text use scenery node - "no-html-constructors": 2, - // - // Custom rule for avoiding Math.sign which is not supported on IE - "no-math-sign": 2, - // - // Custom rule for avoiding instanceof Array. - "no-instanceof-array": 2, - // - // disallow declaration of variables that are not used in the code (recommended) - // Overriden to allow unused args - "no-unused-vars": [ - 2, - { - "vars": "all", - "args": "none" - } - ], - // "require-jsdoc": [ - // 2 - // ], - // - // require the use of === and !== (fixable) - "eqeqeq": 2, - // - // specify curly brace conventions for all control statements - "curly": 2, - // "no-use-before-define": [ - // 2 - // ], - // TODO: This may be good to have - // "new-cap": [ - // 2 - // ], - // - // disallow use of arguments.caller or arguments.callee - "no-caller": 2, - // - // disallow use of the new operator when not part of an assignment or comparison - "no-new": 2, - // - // controls location of Use Strict Directives - "strict": 2, - // - // Avoid code that looks like two expressions but is actually one - "no-unexpected-multiline": 2, - // - // encourages use of dot notation whenever possible - "dot-notation": 2, - // - // disallow adding to native types - "no-extend-native": 2, - // - // disallow use of assignment in return statement - "no-return-assign": 2, - // - // disallow comparisons where both sides are exactly the same - "no-self-compare": 2, - // - // disallow unnecessary .call() and .apply() - // TODO: Under discussion in https://github.com/phetsims/scenery-phet/issues/193 - // "no-useless-call": 2, - // - // disallow use of undefined when initializing variables - "no-undef-init": 2, - // - // - "require-statement-match": 2, - "phet-io-require-contains-ifphetio": 2, - "require-tandem-support": 0, - // - // Require @public/@private for this.something = result; - "property-visibility-annotation": 0, - "no-property-in-require-statement": 2, - // permit only one var declaration per line, see #390 - "one-var": [ - 2, - "never" - ], - "string-require-statement-match": 2, - // require radix argument for parseInt - "radix": 2, - // require default case for switch statements - "default-case": 2, - // do not allow fall-through cases in switch statements - "no-fallthrough": 2, - // consistently use 'self' as the alias for 'this' - "consistent-this": [ - 2, - "self" - ] - // - // disallow trailing whitespace at the end of lines (fixable) - // "no-trailing-spaces": 2, - // - // USE THIS DURING CODE REVIEW - // specify the maximum length of a line in your program - // "max-len": [ - // 2, - // // this many columns per line - // 120, - // // tab counts for this many spaces - // 4 - // ] - }, - "env": { - "browser": true, - "es6": true - }, - "parserOptions": { - "ecmaVersion": 8 - }, - "globals": { - // Global symbols that are permissible to overwrite ----------------------- - "process": true, - // allow assertions - "assert": true, - // allow slow assertions - "assertSlow": true, - // scenery logging levels - "sceneryLog": true, - // scenery accessibility levels - "sceneryAccessibilityLog": true, - // we actually polyfill this, so allow it to be set - "Float32Array": true, - "phet": true, - "phetio": true, - "aqua": true, - // For use in aqua tests - // underscore, lodash - "_": true, - // read-only globals --------------------------------- - - // Javascript Set - "Set": false, - // jQuery - "$": false, - // for full screen - "ActiveXObject": false, - //for debugging on ipad - "alert": false, - // for Mocha tests - "afterEach": false, - // backbone is currently run outside of requirejs - "Backbone": false, - // for Mocha tests - "beforeEach": false, - // BigRational - "bigRat": false, - // DOM.js - "Blob": false, - // Box2D physics engine - "Box2D": false, - // - "Buffer": false, - // - "canvg": false, - // - "clarinet": false, - // - "clearTimeout": false, - // - "console": false, - // d3.js data visualization library - "d3": false, - // require.js - "define": false, - // for Mocha unit tests - "describe": false, - // - "document": false, - // For qunit - "dot": false, - "equal": false, - // For file loading, see SaveLoadNode in Energy Skate Park: Basics - "FileReader": false, - // for linting Node.js code - "global": false, - // jshashes library, for hashing strings (screenshot comparison) - "Hashes": false, - // for HTML entity parsing - "he": false, - // for HTML => JSON parsing - "himalaya": false, - // for hightlighting - "hljs": false, - //for web audio - "Howl": false, - // - "HTMLCanvasElement": false, - "HTMLImageElement": false, - // for CODAP or other Concord communication - "iframePhone": false, - // DOM.js - "Image": false, - // for Mocha unit tests - "it": false, - // for generating diffs in phetio.js - "jsondiffpatch": false, - // QUnit - "kite": false, - // for using native Map - "Map": false, - // QUnit - "QUnit": false, - // For KaTeX - "katex": false, - // For setting location.href to save to local file, see http"://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file - "location": false, - // LZ-string, for compressing and decompressing strings - "LZString": false, - // PhET-iO - "Metacog": false, - // as used in Gruntfile.js - "module": false, - // For Mobile Safari detection, see http"://stackoverflow.com/questions/3007480/determine-if-user-navigated-from-mobile-safari - "navigator": false, - // Numeric library used in energy skate park - "numeric": false, - "ok": false, - // - "PIXI": false, - // For poly2tri triangulation library - "poly2tri": false, - // Misc - "QueryStringMachine": false, - // - "readFile": false, - // require.js - "require": false, - // - "scenery": false, - // For @mrdoob's stats + frame rate readout component - "Stats": false, - // qunit - "test": false, - // For three.js 3d things - "THREE": false, - // sole/tween.js - "TWEEN": false, - // - "Uint16Array": false, - "Uint32Array": false, - // for khronos webgl-debug.js debugging utilities - "WebGLDebugUtils": false, - // for WebSocket communication - "WebSocket": false, - // - "window": false, - // allow ajax requests directly - "XMLHttpRequest": false, - "toast": false, - "Fourier": false - } +// Copyright 2002-2015 University of Colorado Boulder +// @author Sam Reid +// Note: IDEA wants to shrink all the line breaks in the file, so I'm using // to simulate line breakes where desired +{ + // Use all of the default rules from eslint, unless overriden below. + "extends": "eslint:recommended", + // The new rules, overrides, etc. + "rules": { + // + // Permit console.log statements (we have a lot of them) + // TODO: Find a way to make sure no console.log statements make it to production. Can use the no-console rule + // but we want to be able to use console.log during development. + "no-console": 0, + // + // specify whether backticks, double or single quotes should be used (fixable) + "quotes": [ + 2, + "single" + ], + // No dangling commas, see https://github.com/phetsims/tasks/issues/940 + "comma-dangle": 2, + // Prohibit for...of statements + "no-restricted-syntax": [ + "error", + { + "selector": "ForOfStatement", + "message": "Babel transpiles for...of to use Symbol which is not supported on all our platforms." + } + ], + // + // require or disallow use of semicolons instead of ASI (fixable) + "semi": [ + 2, + "always" + ], + "bad-text": 2, + // + // Custom rule for checking the copyright. + "copyright": 2, + // + // Custom rule for checking TODOs have issues + "todo-should-have-issue": 2, + // + // Custom rule for ensuring that images and text use scenery node + "no-html-constructors": 2, + // + // Custom rule for avoiding Math.sign which is not supported on IE + "no-math-sign": 2, + // + // Custom rule for avoiding instanceof Array. + "no-instanceof-array": 2, + // + // disallow declaration of variables that are not used in the code (recommended) + // Overriden to allow unused args + "no-unused-vars": [ + 2, + { + "vars": "all", + "args": "none" + } + ], + // "require-jsdoc": [ + // 2 + // ], + // + // require the use of === and !== (fixable) + "eqeqeq": 2, + // + // specify curly brace conventions for all control statements + "curly": 2, + // "no-use-before-define": [ + // 2 + // ], + // TODO: This may be good to have + // "new-cap": [ + // 2 + // ], + // + // disallow use of arguments.caller or arguments.callee + "no-caller": 2, + // + // disallow use of the new operator when not part of an assignment or comparison + "no-new": 2, + // + // controls location of Use Strict Directives + "strict": 2, + // + // Avoid code that looks like two expressions but is actually one + "no-unexpected-multiline": 2, + // + // encourages use of dot notation whenever possible + "dot-notation": 2, + // + // disallow adding to native types + "no-extend-native": 2, + // + // disallow use of assignment in return statement + "no-return-assign": 2, + // + // disallow comparisons where both sides are exactly the same + "no-self-compare": 2, + // + // disallow unnecessary .call() and .apply() + // TODO: Under discussion in https://github.com/phetsims/scenery-phet/issues/193 + // "no-useless-call": 2, + // + // disallow use of undefined when initializing variables + "no-undef-init": 2, + // + // + "require-statement-match": 2, + "phet-io-require-contains-ifphetio": 2, + "require-tandem-support": 0, + // + // Require @public/@private for this.something = result; + "property-visibility-annotation": 0, + "no-property-in-require-statement": 2, + // permit only one var declaration per line, see #390 + "one-var": [ + 2, + "never" + ], + "string-require-statement-match": 2, + // require radix argument for parseInt + "radix": 2, + // require default case for switch statements + "default-case": 2, + // do not allow fall-through cases in switch statements + "no-fallthrough": 2, + // consistently use 'self' as the alias for 'this' + "consistent-this": [ + 2, + "self" + ] + // + // disallow trailing whitespace at the end of lines (fixable) + // "no-trailing-spaces": 2, + // + // USE THIS DURING CODE REVIEW + // specify the maximum length of a line in your program + // "max-len": [ + // 2, + // // this many columns per line + // 120, + // // tab counts for this many spaces + // 4 + // ] + }, + "env": { + "browser": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 8 + }, + "globals": { + // Global symbols that are permissible to overwrite ----------------------- + "process": true, + // allow assertions + "assert": true, + // allow slow assertions + "assertSlow": true, + // scenery logging levels + "sceneryLog": true, + // scenery accessibility levels + "sceneryAccessibilityLog": true, + // we actually polyfill this, so allow it to be set + "Float32Array": true, + "phet": true, + "phetio": true, + "aqua": true, + // For use in aqua tests + // underscore, lodash + "_": true, + // read-only globals --------------------------------- + + // Javascript Set + "Set": false, + // jQuery + "$": false, + // for full screen + "ActiveXObject": false, + //for debugging on ipad + "alert": false, + // for Mocha tests + "afterEach": false, + // backbone is currently run outside of requirejs + "Backbone": false, + // for Mocha tests + "beforeEach": false, + // BigRational + "bigRat": false, + // DOM.js + "Blob": false, + // Box2D physics engine + "Box2D": false, + // + "Buffer": false, + // + "canvg": false, + // + "clarinet": false, + // + "clearTimeout": false, + // + "console": false, + // d3.js data visualization library + "d3": false, + // require.js + "define": false, + // for Mocha unit tests + "describe": false, + // + "document": false, + // For qunit + "dot": false, + "equal": false, + // For file loading, see SaveLoadNode in Energy Skate Park: Basics + "FileReader": false, + // for linting Node.js code + "global": false, + // jshashes library, for hashing strings (screenshot comparison) + "Hashes": false, + // for HTML entity parsing + "he": false, + // for HTML => JSON parsing + "himalaya": false, + // for hightlighting + "hljs": false, + //for web audio + "Howl": false, + // + "HTMLCanvasElement": false, + "HTMLImageElement": false, + // for CODAP or other Concord communication + "iframePhone": false, + // DOM.js + "Image": false, + // for Mocha unit tests + "it": false, + // for generating diffs in phetio.js + "jsondiffpatch": false, + // QUnit + "kite": false, + // for using native Map + "Map": false, + // QUnit + "QUnit": false, + // For KaTeX + "katex": false, + // For setting location.href to save to local file, see http"://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file + "location": false, + // LZ-string, for compressing and decompressing strings + "LZString": false, + // PhET-iO + "Metacog": false, + // as used in Gruntfile.js + "module": false, + // For Mobile Safari detection, see http"://stackoverflow.com/questions/3007480/determine-if-user-navigated-from-mobile-safari + "navigator": false, + // Numeric library used in energy skate park + "numeric": false, + "ok": false, + // + "PIXI": false, + // For poly2tri triangulation library + "poly2tri": false, + // Misc + "QueryStringMachine": false, + // + "readFile": false, + // require.js + "require": false, + // + "scenery": false, + // For @mrdoob's stats + frame rate readout component + "Stats": false, + // qunit + "test": false, + // For three.js 3d things + "THREE": false, + // sole/tween.js + "TWEEN": false, + // + "Uint16Array": false, + "Uint32Array": false, + // for khronos webgl-debug.js debugging utilities + "WebGLDebugUtils": false, + // for WebSocket communication + "WebSocket": false, + // + "window": false, + // allow ajax requests directly + "XMLHttpRequest": false, + "toast": false, + "Fourier": false + } } \ No newline at end of file diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js index 7a6b2c19f..f4d115c99 100644 --- a/js/grunt/Gruntfile.js +++ b/js/grunt/Gruntfile.js @@ -187,7 +187,7 @@ module.exports = function( grunt ) { const allHTML = !!grunt.option( 'allHTML' ); const localesOption = grunt.option( 'locales' ) || 'en'; // Default back to English for now - for ( let brand of brands ) { + for ( let brand of brands ) { // eslint-disable-line no-restricted-syntax grunt.log.writeln( `Building brand: ${brand}` ); await buildRunnable( repo, minifyOptions, instrument, allHTML, brand, localesOption ); diff --git a/js/grunt/buildRunnable.js b/js/grunt/buildRunnable.js index 8a4629844..3eacbaaee 100644 --- a/js/grunt/buildRunnable.js +++ b/js/grunt/buildRunnable.js @@ -164,7 +164,7 @@ module.exports = async function( repo, minifyOptions, instrument, allHTML, brand // {{locale}}.html if ( brand !== 'phet-io' ) { - for ( let locale of locales ) { + for ( let locale of locales ) { // eslint-disable-line no-restricted-syntax const initializationScript = getInitializationScript( _.extend( { locale, includeAllLocales: false, @@ -283,7 +283,7 @@ module.exports = async function( repo, minifyOptions, instrument, allHTML, brand { width: 128, height: 84 }, { width: 600, height: 394 } ]; - for ( let size of thumbnailSizes ) { + for ( let size of thumbnailSizes ) { // eslint-disable-line no-restricted-syntax grunt.file.write( `${buildDir}/${repo}-${size.width}.png`, await generateThumbnails( repo, size.width, size.height ) ); } diff --git a/js/grunt/commitsSince.js b/js/grunt/commitsSince.js index 1ce844f02..95459905a 100644 --- a/js/grunt/commitsSince.js +++ b/js/grunt/commitsSince.js @@ -28,7 +28,7 @@ const grunt = require( 'grunt' ); module.exports = async function( repo, dateString ) { let output = ''; - for ( let dependency of getPhetLibs( repo ) ) { + for ( let dependency of getPhetLibs( repo ) ) { // eslint-disable-line no-restricted-syntax output += `${dependency} since ${dateString} ----------------------------------------------\n`; output += await execute( 'git', [ 'log', `--since="${dateString}"`, '--pretty=tformat:"%h | %ci | %cn | %s"' ], { cwd: `../${dependency}` } ); } diff --git a/js/grunt/getDependencies.js b/js/grunt/getDependencies.js index 1a7d3dcbb..0c8c2a6a5 100644 --- a/js/grunt/getDependencies.js +++ b/js/grunt/getDependencies.js @@ -39,7 +39,7 @@ module.exports = async function( repo ) { comment: `# ${repo} ${version} ` + ( new Date().toString() ) }; - for ( let dependency of dependencies ) { + for ( let dependency of dependencies ) { // eslint-disable-line no-restricted-syntax assert( !dependenciesInfo.dependency, 'there was already a dependency named ' + dependency ); if ( !grunt.file.exists( `../${dependency}` ) ) { diff --git a/js/grunt/reportThirdParty.js b/js/grunt/reportThirdParty.js index bfb84ae2c..e3e58ef24 100644 --- a/js/grunt/reportThirdParty.js +++ b/js/grunt/reportThirdParty.js @@ -59,7 +59,7 @@ module.exports = async function() { // TODO: don't use this from chipper! const activeSims = fs.readFileSync( '../perennial/data/active-sims', 'utf-8' ).trim().split( '\n' ).map( sim => sim.trim() ); - for ( let sim of activeSims ) { + for ( let sim of activeSims ) { // eslint-disable-line no-restricted-syntax const url = `https://${serverName}/sims/html/${sim}/latest/${sim}_en.html`; console.log( `downloading ${sim}` ); try { diff --git a/js/grunt/updateCopyrightDates.js b/js/grunt/updateCopyrightDates.js index 70c0f6a84..002e675f8 100644 --- a/js/grunt/updateCopyrightDates.js +++ b/js/grunt/updateCopyrightDates.js @@ -25,7 +25,7 @@ module.exports = async function( repo, predicate = () => true ) { } ); relativeFiles = relativeFiles.filter( file => file.startsWith( 'js/' ) ).filter( predicate ); - for ( let relativeFile of relativeFiles ) { + for ( let relativeFile of relativeFiles ) { // eslint-disable-line no-restricted-syntax await updateCopyrightDate( repo, relativeFile ); } }; diff --git a/test/chainsBuildTest.js b/test/chainsBuildTest.js index 674492e32..68b6852c3 100644 --- a/test/chainsBuildTest.js +++ b/test/chainsBuildTest.js @@ -33,7 +33,7 @@ function assertChainsExistence( assert, brand, options ) { if ( locales.includes( 'en' ) ) { assertFileExistence( assert, '../chains/build/phet/chains_en_iframe_phet.html' ); } - for ( let locale of locales ) { + for ( let locale of locales ) { // eslint-disable-line no-restricted-syntax assertFileExistence( assert, `../chains/build/phet/chains_${locale}_phet.html` ); } assertFileExistence( assert, '../chains/build/phet/chains-128.png' );