-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a rule that tries to check for property visibility annotations,…
… see phetsims/chipper#618
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2016, University of Colorado Boulder | ||
/** | ||
* @fileoverview Rule to check that an assignment in a constructor provides @public or @private visibility annotation | ||
* Developed with https://astexplorer.net/ | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
* @copyright 2016 University of Colorado Boulder | ||
*/ | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function( context ) { | ||
'use strict'; | ||
|
||
return { | ||
|
||
AssignmentExpression: function propertyVisibilityAnnotation( node ) { | ||
|
||
if ( node.left && node.left && node.left.object && node.left.object.type === 'ThisExpression' ) { | ||
var leadingComments = node.parent.leadingComments; | ||
var i; | ||
var a; | ||
var isAnnotated = false; | ||
if ( leadingComments ) { | ||
for ( i = 0; i < leadingComments.length; i++ ) { | ||
a = leadingComments[ i ]; | ||
if ( a.value.indexOf( '@public' ) >= 0 || a.value.indexOf( '@private' ) >= 0 ) { | ||
isAnnotated = true; | ||
} | ||
} | ||
} | ||
|
||
var trailingComments = node.parent.trailingComments; | ||
if ( trailingComments ) { | ||
for ( i = 0; i < trailingComments.length; i++ ) { | ||
a = trailingComments[ i ]; | ||
if ( a.value.indexOf( '@public' ) >= 0 || a.value.indexOf( '@private' ) >= 0 ) { | ||
isAnnotated = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( node.parent && node.parent.parent && node.parent.parent.parent ) { | ||
var parentFunction = node.parent.parent.parent; | ||
if ( parentFunction.id && parentFunction.id.name ) { | ||
if ( parentFunction.type === 'FunctionDeclaration' && parentFunction.id.name[ 0 ].toUpperCase() === parentFunction.id.name[ 0 ] ) { | ||
if ( !isAnnotated ) { | ||
context.report( { | ||
node: node, | ||
loc: node.loc.start, | ||
message: 'missing visibility annotation' | ||
} ); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = [ | ||
// JSON Schema for rule options goes here | ||
]; |