Skip to content

Commit

Permalink
Make eslint-disable-line bad text when no rule is provided, see #1313
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 11, 2022
1 parent 61eee81 commit 0392937
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
13 changes: 12 additions & 1 deletion eslint/rules/bad-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,18 @@ module.exports = function( context ) {
},

// Should have a period before "<", see https://github.com/phetsims/chipper/issues/1005 and https://github.com/phetsims/chipper/issues/1003
{ id: 'Type<Parameter> (add a dot)', regex: /{[^\n:]*[A-z]<[A-z][|'<>A-z]+>[^\n:{}]*}}/ }
{ id: 'Type<Parameter> (add a dot)', regex: /{[^\n:]*[A-z]<[A-z][|'<>A-z]+>[^\n:{}]*}}/ },

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

// Report the error on the previous line so it doesn't get disabled
lineNumberDelta: -1
}
];

return {
Expand Down
7 changes: 5 additions & 2 deletions eslint/rules/getBadTextTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ module.exports = ( ruleName, badTexts, context ) => {
for ( let i = 0; i < codeLines.length; i++ ) {
const lineString = codeLines[ i ];

// lines are 1 based, codeLines array is 0 based
const badLineNumber = i + 1;
// lines are 1 based, codeLines array is 0 based. Can also add a delta so that rules about
// disable-line can report on an adjacent line. Seems to work correctly if badLineNumber === 0
const badLineNumber = i + 1 + ( forbiddenText.lineNumberDelta || 0 );

// only test regex if provided
if ( forbiddenText.regex ) {
Expand Down Expand Up @@ -126,6 +127,8 @@ module.exports = ( ruleName, badTexts, context ) => {
* then the bad text will only be checked in code, and not via each line.
* @property {RegExp} [regex] - if provided, instead of checking the id as a string, test each line with this regex.
* @property {function} [predicate] - if provided, instead of checking the id as a string, test each line with this function
* @property {number} [lineNumberDelta] - if provided, instead report the error on a different line, to avoid lines
* that have eslint-disable directives
*/
};

Expand Down
2 changes: 1 addition & 1 deletion eslint/rules/phet-io-require-contains-ifphetio.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function( context ) {
// {
// 'type': 'Literal',
// 'value': 'FUNCTION_BUILDER/equations/EquationsScreen',
// 'raw': "'FUNCTION_BUILDER/equations/EquationsScreen'"//eslint-disable-line
// 'raw': "'FUNCTION_BUILDER/equations/EquationsScreen'"//eslint-disable-line ???
// }
// ]
// }
Expand Down
2 changes: 1 addition & 1 deletion eslint/rules/require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function( context ) {
// {
// 'type': 'Literal',
// 'value': 'FUNCTION_BUILDER/equations/EquationsScreen',
// 'raw': "'FUNCTION_BUILDER/equations/EquationsScreen'"//eslint-disable-line
// 'raw': "'FUNCTION_BUILDER/equations/EquationsScreen'"//eslint-disable-line ???
// }
// ]
// }
Expand Down

0 comments on commit 0392937

Please sign in to comment.