-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eslint rule to make sure imports are on a single line, see phetsims/p…
- Loading branch information
1 parent
8f4c78d
commit a2867af
Showing
2 changed files
with
54 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,51 @@ | ||
// Copyright 2016-2020, University of Colorado Boulder | ||
/** | ||
* @fileoverview Rule to check that import statements are on single lines. Automated tools | ||
* and processes at PhET assume that imports are on a single line so this is important to enforce. | ||
* | ||
* @author Jesse Greenberg (PhET Interactive Simulations) | ||
* @copyright 2020 University of Colorado Boulder | ||
*/ | ||
|
||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = context => { | ||
|
||
return { | ||
|
||
ImportDeclaration: node => { | ||
if ( node.loc.start.line !== node.loc.end.line ) { | ||
|
||
// AST JSON might look something like: | ||
// { | ||
// "type": "ImportDeclaration", | ||
// "specifiers": [ | ||
// { | ||
// "type": "ImportDefaultSpecifier", | ||
// "local": { | ||
// "type": "Identifier", | ||
// "name": "EnergySkateParkColorScheme", | ||
// } | ||
// } | ||
// ] | ||
// } | ||
node.specifiers.forEach( specifier => { | ||
context.report( { | ||
node: node, | ||
loc: node.loc, | ||
message: specifier.local.name + ': import statement should be on a single line.' | ||
} ); | ||
} ); | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = [ | ||
// JSON Schema for rule options goes here | ||
]; |