Skip to content

Commit

Permalink
fix copyright and lint errors, phetsims/phet-info#150
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Dec 18, 2020
1 parent 6887eb5 commit 325ce1f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
103 changes: 52 additions & 51 deletions js/grunt/format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020, Nick Crews
// Copyright 2020, University of Colorado Boulder

/**
* Runs the formatting rules on the specified files.
Expand All @@ -9,67 +9,67 @@
'use strict';

// modules
const beautify = require( 'js-beautify' );
const beautify = require( 'js-beautify' ); // eslint-disable-line
const fs = require( 'fs' );
const grunt = require( 'grunt' );
const sortImports = require( './sortImports' );

const OPTIONS = {
"html": {
"allowed_file_extensions": [ "htm", "html", "xhtml", "shtml", "xml", "svg" ],
"brace_style": "collapse",
"end_with_newline": false,
"indent_char": " ",
"indent_handlebars": false,
"indent_inner_html": false,
"indent_size": 2,
"indent_scripts": "keep",
"max_preserve_newlines": 1,
"preserve_newlines": true,
"unformatted": [ "a", "span", "img", "code", "pre", "sub", "sup", "em", "strong", "b", "i", "u", "strike", "big", "small", "pre", "h1", "h2", "h3", "h4", "h5", "h6" ],
"wrap_line_length": 0
'html': {
'allowed_file_extensions': [ 'htm', 'html', 'xhtml', 'shtml', 'xml', 'svg' ],
'brace_style': 'collapse',
'end_with_newline': false,
'indent_char': ' ',
'indent_handlebars': false,
'indent_inner_html': false,
'indent_size': 2,
'indent_scripts': 'keep',
'max_preserve_newlines': 1,
'preserve_newlines': true,
'unformatted': [ 'a', 'span', 'img', 'code', 'pre', 'sub', 'sup', 'em', 'strong', 'b', 'i', 'u', 'strike', 'big', 'small', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ],
'wrap_line_length': 0
},
"css": {
"allowed_file_extensions": [ "css", "scss", "sass", "less" ],
"end_with_newline": false,
"newline_between_rules": true,
"indent_char": " ",
"indent_size": 2,
"selector_separator": " ",
"selector_separator_newline": true
'css': {
'allowed_file_extensions': [ 'css', 'scss', 'sass', 'less' ],
'end_with_newline': false,
'newline_between_rules': true,
'indent_char': ' ',
'indent_size': 2,
'selector_separator': ' ',
'selector_separator_newline': true
},
"js": {
"allowed_file_extensions": [ "js", "json", "jshintrc", "jsbeautifyrc", "sublime-settings" ],
"brace_style": "collapse-preserve-inline",
"break_chained_methods": false,
"e4x": false,
"end_with_newline": true,
"indent_char": " ",
"indent_level": 0,
"indent_size": 2,
"indent_with_tabs": false,
"jslint_happy": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"max_preserve_newlines": 0,
"preserve_newlines": true,
"space_after_anon_function": false,
"space_before_conditional": true,
"space_in_empty_paren": false,
"space_in_paren": true,
"unescape_strings": false,
"wrap_line_length": 0
'js': {
'allowed_file_extensions': [ 'js', 'json', 'jshintrc', 'jsbeautifyrc', 'sublime-settings' ],
'brace_style': 'collapse-presever-inline',
'break_chained_methods': false,
'e4x': false,
'end_with_newline': true,
'indent_char': ' ',
'indent_level': 0,
'indent_size': 2,
'indent_with_tabs': false,
'jslint_happy': false,
'keep_array_indentation': false,
'keep_function_indentation': false,
'max_preserve_newlines': 0,
'preserve_newlines': true,
'space_after_anon_function': false,
'space_before_conditional': true,
'space_in_empty_paren': false,
'space_in_paren': true,
'unescape_strings': false,
'wrap_line_length': 0
}
}
};

function formatFile( absPath, verifyOnly = false ) {
let before = fs.readFileSync( absPath, 'utf-8' );
const before = fs.readFileSync( absPath, 'utf-8' );
const formatted = beautify.js( before, OPTIONS );
if ( !verifyOnly ){
if ( !verifyOnly ) {
fs.writeFileSync( absPath, formatted, 'utf-8' );
}
const alreadySorted = sortImports( absPath, verifyOnly );
return alreadySorted && ( before == formatted );
return alreadySorted && ( before === formatted );
}

/**
Expand All @@ -79,12 +79,13 @@ function formatFile( absPath, verifyOnly = false ) {
* @param {Array.<string>} repos
* @param {boolean} verifyOnly - Don't rewrite files
*/
module.exports = function( repos, verifyOnly = false) {
module.exports = function( repos, verifyOnly = false ) {

repos.forEach( repo => {
grunt.file.recurse(
`../${repo}/js`,
absPath => formatFile( absPath, verifyOnly )
) } );
);
} );

}
};
4 changes: 2 additions & 2 deletions js/grunt/sortImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ module.exports = function( file, verifyOnly = false ) {
}

const after = lines.join( '\n' );
if (!verifyOnly){
if ( !verifyOnly ) {
fs.writeFileSync( file, after, 'utf-8' );
}
return (after == before);
return ( after === before );
};

0 comments on commit 325ce1f

Please sign in to comment.