From 828c6e3391d71c84e280d6c5f11d6e253e3f1d04 Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Sat, 7 Oct 2023 09:45:33 -0600 Subject: [PATCH] turn on linting for HTML files in the project, https://github.com/phetsims/chipper/issues/1405 --- eslint/.eslintignore | 6 +++++- eslint/.eslintrc.js | 12 ++++++++++++ eslint/rules/bad-text.js | 16 ++++------------ eslint/rules/copyright.js | 6 ++++++ eslint/sim_eslintrc.js | 11 ++++++++++- js/grunt/lint.js | 4 ++-- package.json | 1 + 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/eslint/.eslintignore b/eslint/.eslintignore index 41a082115..42755cf07 100644 --- a/eslint/.eslintignore +++ b/eslint/.eslintignore @@ -5,6 +5,7 @@ **/snapshots **/js/parser/svgPath.js **/templates/*.js +**/templates/*.html **/js/**/*Strings.ts **/images/**/*_cur.ts **/images/**/*_jpg.ts @@ -19,6 +20,9 @@ ../phet-io-website/root/assets/js/QueryStringMachine_1.0.js ../phet-io-website/root/assets/js/QueryStringMachine_2.0.js ../phet-io-website/root/assets/js/phet-io-ga.js +../phet-io-wrappers/common/html/customPhetioWrapperTemplateSkeleton.html +../phet-io-wrappers/common/html/standardPhetioWrapperTemplateSkeleton.html ../chipper/dist ../scenery/js/display/swash/pkg -../scenery/js/display/guillotiere/pkg \ No newline at end of file +../scenery/js/display/guillotiere/pkg +../yotta/js/reports/by-simulation.html \ No newline at end of file diff --git a/eslint/.eslintrc.js b/eslint/.eslintrc.js index 1f5c3fad2..5c4ad76a2 100644 --- a/eslint/.eslintrc.js +++ b/eslint/.eslintrc.js @@ -16,7 +16,18 @@ module.exports = { // Without a parser, .js files are linted without es6 transpilation. Use the same parser that we use for TypeScript. parser: '@typescript-eslint/parser', + // Lint javascript in HTML files too + plugins: [ 'html' ], + overrides: [ + { + files: [ '*.html' ], + rules: { + // DUPLICATION ALERT, this overrides the base rule, just for HTML. + 'no-multiple-empty-lines': [ 'error', { max: 2, maxBOF: 2, maxEOF: 1 } ], + 'bad-sim-text': 'off' + } + }, { // For .ts files, the following configuration will be used @@ -1345,6 +1356,7 @@ module.exports = { 'no-multi-spaces': [ 'error', { ignoreEOLComments: true } ], // Disallow multiple empty lines + // DUPLICATION ALERT, this is overridden for html files, see above "overrides" 'no-multiple-empty-lines': [ 'error', { max: 2, maxBOF: 0, maxEOF: 1 } ], // Disallow all tabs diff --git a/eslint/rules/bad-text.js b/eslint/rules/bad-text.js index be5ad53ed..6dbf37419 100644 --- a/eslint/rules/bad-text.js +++ b/eslint/rules/bad-text.js @@ -134,10 +134,8 @@ module.exports = function( context ) { // eslint disable line directives must have an explanation { - id: 'eslint-disable-line-directives-must-have-explanation', - predicate: line => { - return !line.trim().endsWith( 'eslint-disable-line' ); - }, + id: 'eslint-disable-line directives must have explanation', + predicate: line => !line.trim().endsWith( 'eslint-disable-line' ), // Report the error on the previous line so it doesn't get disabled lineNumberDelta: -1 @@ -145,14 +143,8 @@ module.exports = function( context ) { // eslint disable next line directives must have an explanation { - id: 'eslint-disable-next-line-directives-must-have-explanation', - predicate: line => { - if ( line.trim().endsWith( 'eslint-disable-next-line' ) ) { - console.log( 'gotcha' ); - } - - return !line.trim().endsWith( 'eslint-disable-next-line' ); - } + id: 'eslint-disable-next-line directives must have explanation', + predicate: line => !line.trim().endsWith( 'eslint-disable-next-line' ) } ]; diff --git a/eslint/rules/copyright.js b/eslint/rules/copyright.js index ea5403b95..b56b43ffa 100644 --- a/eslint/rules/copyright.js +++ b/eslint/rules/copyright.js @@ -18,6 +18,12 @@ module.exports = function( context ) { // Get the whole source code, not for node only. const comments = context.getSourceCode().getAllComments(); + const isHTML = context.getFilename().endsWith( '.html' ); + + if ( isHTML ) { + return; + } + if ( !comments || comments.length === 0 ) { context.report( { node: node, diff --git a/eslint/sim_eslintrc.js b/eslint/sim_eslintrc.js index 9fdea279d..0d6460968 100644 --- a/eslint/sim_eslintrc.js +++ b/eslint/sim_eslintrc.js @@ -9,5 +9,14 @@ module.exports = { extends: './.eslintrc.js', rules: { 'bad-sim-text': 'error' - } + }, + overrides: [ + { + // Most html files don't need to behave like sims + files: [ '*.html' ], + rules: { + 'bad-sim-text': 'off' + } + } + ] }; \ No newline at end of file diff --git a/js/grunt/lint.js b/js/grunt/lint.js index f96bcd5b6..ea9eb168b 100644 --- a/js/grunt/lint.js +++ b/js/grunt/lint.js @@ -19,7 +19,7 @@ const CacheLayer = require( '../common/CacheLayer' ); const crypto = require( 'crypto' ); // constants -const EXCLUDE_REPOS = []; +const EXCLUDE_REPOS = [ 'fenster', 'decaf', 'scenery-lab-demo' ]; // "Pattern" is really a path, we assume here that gruntfiles help keep the right directory stucture and can just pop // out of the repo running the command @@ -80,7 +80,7 @@ const lintOneRepo = async ( repo, options ) => { // Our custom rules live here rulePaths: [ '../chipper/eslint/rules' ], - extensions: [ '.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs' ], + extensions: [ '.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.html' ], // If no lintable files are found, it is not an error errorOnUnmatchedPattern: false diff --git a/package.json b/package.json index b0575d24d..83439deee 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@typescript-eslint/parser": "~6.1.0", "@typescript-eslint/eslint-plugin": "~6.1.0", "@typescript-eslint/utils": "~6.1.0", + "eslint-plugin-html": "~7.1.0", "@webgpu/types": "~0.1.34", "archiver": "~5.3.0", "axios": "~0.21.4",