Skip to content

Commit

Permalink
turn on linting for HTML files in the project, #1405
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 7, 2023
1 parent 627cf09 commit 828c6e3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
6 changes: 5 additions & 1 deletion eslint/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**/snapshots
**/js/parser/svgPath.js
**/templates/*.js
**/templates/*.html
**/js/**/*Strings.ts
**/images/**/*_cur.ts
**/images/**/*_jpg.ts
Expand All @@ -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
../scenery/js/display/guillotiere/pkg
../yotta/js/reports/by-simulation.html
12 changes: 12 additions & 0 deletions eslint/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions eslint/rules/bad-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,17 @@ 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
},

// 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' )
}
];

Expand Down
6 changes: 6 additions & 0 deletions eslint/rules/copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion eslint/sim_eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
]
};
4 changes: 2 additions & 2 deletions js/grunt/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 828c6e3

Please sign in to comment.