Skip to content

Commit

Permalink
custom lint rules should be linted as node code, #811
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 4, 2019
1 parent 9f69f9e commit 5c0e158
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 21 deletions.
10 changes: 10 additions & 0 deletions eslint/rules/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2019, University of Colorado Boulder
// @author Chris Klusendorf

'use strict';

module.exports = {

// Use all of the default rules from eslint file for node code.
"extends": "../node_eslintrc.js"
};
7 changes: 5 additions & 2 deletions eslint/rules/bad-sim-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
* @author Sam Reid (PhET Interactive Simulations)
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

/* eslint-env node */
'use strict';

module.exports = function( context ) {
'use strict';

const getBadTextTester = require( './getBadTextTester' );

// see getBadTextTester for schema.
var forbiddenTextObjects = [
const forbiddenTextObjects = [

// babel doesn't support compiling static getters, see https://github.com/phetsims/tasks/issues/983
{ id: ' static get ', codeOnly: true, codeTokens: [ 'static', 'get' ] },
Expand Down
5 changes: 4 additions & 1 deletion eslint/rules/bad-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*
* @author Sam Reid (PhET Interactive Simulations)
*/

/* eslint-env node */
'use strict';

module.exports = function( context ) {
'use strict';

const getBadTextTester = require( './getBadTextTester' );

Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2015 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

Expand Down
6 changes: 4 additions & 2 deletions eslint/rules/dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2015 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

// the following holds the possible ways to register various PhET listeners and observers
// TODO: derivedProperty
Expand Down Expand Up @@ -38,7 +40,7 @@ module.exports = function( context ) {
if( OBSERVER_REGISTRATIONS.hasOwnProperty( key ) ) {
if( calleeName === OBSERVER_REGISTRATIONS[ key ] ) {
// we have found an observer registration, start at the root and look through its tokens for dispose
var disposeFound = false;
let disposeFound = false;
const rootNode = context.getSourceCode().ast;
if( rootNode &&
rootNode.tokens ) {
Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/getBadTextTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @author Jesse Greenberg (PhET Interactive Simulations)
*/

/* eslint-env node */
'use strict';

const assert = require( 'assert' );

/**
Expand All @@ -17,7 +20,6 @@ const assert = require( 'assert' );
* @returns {function(node:Object)} - function that reports any bad text lint errors to the context
*/
module.exports = ( badTexts, context ) => {
'use strict';

return node => {
const sourceCode = context.getSourceCode();
Expand Down
5 changes: 4 additions & 1 deletion eslint/rules/no-extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*
* @author Michael Kauzmann (PhET Interactive Simulations)
*/

/* eslint-env node */
'use strict';

module.exports = context => {
'use strict';

const badTextParts = [ '_', '.', 'extend' ];
return {
Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/no-html-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
* @copyright 2016-2017 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

// names of the native JavaScript constructors that clash with PhET type names
const nativeConstructors = [ 'Image', 'Range', 'Text', 'Node', 'Event' ];
Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/no-instanceof-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2018 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {
BinaryExpression: function( node ) {
Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/no-math-sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2017 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/no-property-in-require-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2016 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/phet-io-require-contains-ifphetio.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2016 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/phet-object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* original file: https://github.com/eslint/eslint/blob/550de1e611a1e9af873bcb18d74cf2056e8d2e1b/lib/rules/object-shorthand.js
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function( context ) {
'use strict';

return {
'Property:exit'( node ) {
Expand Down
6 changes: 4 additions & 2 deletions eslint/rules/property-visibility-annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
* @copyright 2016 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

AssignmentExpression: function propertyVisibilityAnnotation( node ) {
let isAnnotated = false;

if ( node.left && node.left && node.left.object && node.left.object.type === 'ThisExpression' ) {
const leadingComments = node.parent.leadingComments;
let i;
let a;
var isAnnotated = false;
if ( leadingComments ) {
for ( i = 0; i < leadingComments.length; i++ ) {
a = leadingComments[ i ];
Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2015 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

return {

Expand Down
4 changes: 3 additions & 1 deletion eslint/rules/string-require-statement-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @copyright 2015 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function( context ) {
'use strict';

// Adapted from Stack Overflow, see http://stackoverflow.com/questions/25085306/javascript-space-separated-string-to-camelcase
function toCamelCase( string ) {
Expand Down
8 changes: 5 additions & 3 deletions eslint/rules/todo-should-have-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* @copyright 2015 University of Colorado Boulder
*/

/* eslint-env node */
'use strict';

module.exports = function( context ) {
'use strict';

// Whitelist of directories to check that TODOs have GitHub issues
const directoriesToRequireIssues = [ /joist[/\\]js/ ];
Expand All @@ -17,7 +19,7 @@ module.exports = function( context ) {

// Check whether the given directory matches the whitelist
let directoryShouldBeChecked = false;
for ( var i = 0; i < directoriesToRequireIssues.length; i++ ) {
for ( let i = 0; i < directoriesToRequireIssues.length; i++ ) {
const d = directoriesToRequireIssues[ i ];
if ( context.getFilename().match( d ) ) {
directoryShouldBeChecked = true;
Expand All @@ -29,7 +31,7 @@ module.exports = function( context ) {
const comments = context.getSourceCode().getAllComments();

if ( comments ) {
for ( i = 0; i < comments.length; i++ ) {
for ( let i = 0; i < comments.length; i++ ) {
const comment = comments[ i ];

if ( comment.value.indexOf( 'TODO' ) >= 0 ) {
Expand Down

0 comments on commit 5c0e158

Please sign in to comment.