Skip to content

Commit 01e1138

Browse files
committed
Finish conforming codebase to new eslintrc
1 parent 58d05c2 commit 01e1138

10 files changed

+64
-51
lines changed

.editorconfig

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@ root = true
88
end_of_line = lf
99
insert_final_newline = true
1010

11-
# Avoid trailing whitespace
1211
[*.js]
12+
# Avoid trailing whitespace
1313
trim_trailing_whitespace = true
14-
1514
# Set default charset for JS files
16-
[*.js]
1715
charset = utf-8
18-
19-
# Tab indentation (no size specified)
20-
[*.js]
16+
# Tab indentation
2117
indent_style = tab
22-
indent_size = tab
2318
tab_width = 2
2419

2520
# Matches the exact files either package.json or .travis.yml

.eslintignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# /node_modules/* and /bower_components/* in the project root are ignored by default
2+
3+
# Ignore built files
4+
browser/
5+
6+
# Ignore generated coverage directory
7+
coverage/
8+
9+
# Ignore documentation site scaffold
10+
documentation/
11+
12+
# Ignore local testing script
13+
test.js

Gruntfile.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
'use strict';
77

88
module.exports = function( grunt ) {
9-
grunt.initConfig({
10-
pkg: grunt.file.readJSON( 'package.json' )
11-
});
9+
grunt.initConfig( {
10+
pkg: grunt.file.readJSON( 'package.json' ),
11+
} );
1212

1313
// Individual tasks are defined within build/grunt
1414
grunt.loadTasks( 'build/grunt' );
1515

1616
grunt.registerTask( 'docs', [
1717
'clean',
1818
'generate_readme_docs',
19-
'zip'
20-
]);
19+
'zip',
20+
] );
2121
};

build/.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
'rules': {
3+
'no-console': [ 'off' ],
4+
},
5+
};

build/grunt/zip.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
module.exports = function( grunt ) {
44
grunt.config.set( 'zip', {
5-
bundle: {
6-
cwd: 'browser',
7-
src: [ 'browser/**/*', 'LICENSE' ],
8-
dest: 'documentation/wpapi.zip',
9-
},
10-
} );
5+
bundle: {
6+
cwd: 'browser',
7+
src: [ 'browser/**/*', 'LICENSE' ],
8+
dest: 'documentation/wpapi.zip',
9+
},
10+
} );
1111

1212
grunt.loadNpmTasks( 'grunt-zip' );
1313
};

build/scripts/generate-docs-markdown.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
'use strict';
32

43
const fs = require( 'fs' );
@@ -61,7 +60,7 @@ const titleToSlug = title => title
6160
.split( /\s+/ )
6261
.join( '-' );
6362

64-
const fileHeader = title => {
63+
const fileHeader = ( title ) => {
6564
const slug = titleToSlug( title );
6665
return `---\nlayout: page\ntitle: ${ title }\npermalink: /${ slug }/\n---`;
6766
};
@@ -73,12 +72,12 @@ const isTitle = token => token.match( titleRE );
7372

7473
const getTitle = token => token.replace( titleRE, '$1' ).trim();
7574

76-
const getLevel = mdHeading => {
75+
const getLevel = ( mdHeading ) => {
7776
const match = mdHeading.match( /#+/ );
7877
return match ? match[ 0 ].length : -1;
7978
};
8079

81-
const getContents = entry => {
80+
const getContents = ( entry ) => {
8281
// Strip any top-level headings: those are rendered as titles elsewhere
8382
const fileContents = entry.tokens.join( '' ).replace( /^# [^\n]+/, '' );
8483
const title = fileHeader( entry.title );
@@ -102,7 +101,7 @@ const readFile = sourcePath => new Promise( ( resolve, reject ) => {
102101
} );
103102

104103
const writeFile = ( outputPath, fileContents ) => new Promise( ( resolve, reject ) => {
105-
fs.writeFile( outputPath, fileContents, ( err, result ) => {
104+
fs.writeFile( outputPath, fileContents, ( err ) => {
106105
if ( err ) {
107106
return reject( err );
108107
}
@@ -111,7 +110,7 @@ const writeFile = ( outputPath, fileContents ) => new Promise( ( resolve, reject
111110
} );
112111
} );
113112

114-
const copyFile = ( sourcePath, title ) => readFile( sourcePath ).then( contents => {
113+
const copyFile = ( sourcePath, title ) => readFile( sourcePath ).then( ( contents ) => {
115114
const outputPath = path.join( docsDir, `${ titleToSlug( title ) }.md` );
116115
return writeFile( outputPath, getContents( {
117116
title: title,
@@ -120,7 +119,7 @@ const copyFile = ( sourcePath, title ) => readFile( sourcePath ).then( contents
120119
} );
121120

122121
// Break the README into individual files
123-
const readmeOutput = readFile( readmePath ).then( contents => {
122+
const readmeOutput = readFile( readmePath ).then( ( contents ) => {
124123
const tokens = contents.split( /(\n+#+ .*\n+)/ );
125124
const entries = [];
126125
let entry = null;
@@ -192,7 +191,7 @@ const changelogOutput = copyFile( changelogPath, 'Changelog' );
192191
const licenseOutput = copyFile( licensePath, 'License' );
193192

194193
// Build the template context to use with the
195-
const templateContext = readmeOutput.then( entries => {
194+
const templateContext = readmeOutput.then( ( entries ) => {
196195
return entries.reduce( ( context, entry ) => {
197196
const isAboutPage = entry.slug === 'about';
198197
if ( isAboutPage ) {
@@ -217,15 +216,15 @@ const fileAndContext = filePath => Promise.all( [
217216
} ) );
218217

219218
// Create the index HTML page
220-
const indexOutput = fileAndContext( indexTemplatePath ).then( result => {
219+
const indexOutput = fileAndContext( indexTemplatePath ).then( ( result ) => {
221220
console.log( 'index' );
222221
const outputPath = path.join( docsDir, 'index.html' );
223222
const fileContents = combyne( result.template ).render( result.context );
224223
return writeFile( outputPath, fileContents );
225224
} );
226225

227226
// Create the Error 404 page
228-
const err404Output = fileAndContext( err404TemplatePath ).then( result => {
227+
const err404Output = fileAndContext( err404TemplatePath ).then( ( result ) => {
229228
console.log( '404' );
230229
const outputPath = path.join( docsDir, '404.html' );
231230
const fileContents = combyne( result.template ).render( result.context );
@@ -240,4 +239,4 @@ module.exports = Promise.all( [
240239
indexOutput,
241240
err404Output,
242241
] )
243-
.catch( err => console.log( err && err.stack ) );
242+
.catch( err => console.log( err && err.stack ) );

build/scripts/release-docs.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
'use strict';
32

43
const fs = require( 'fs' );
@@ -25,7 +24,7 @@ const OMIT_FILE_RE = /^\.|\.lock|\.combyne$/;
2524
// incorrect but still helpful assumption that no file extension means that
2625
// something is a directory. This means Gemfile and other no-ext files are
2726
// unnecessarily deleted, but it makes things work with minimal complexity.
28-
const PROBABLY_A_DIRECTORY_RE = /^[^\.]+$/;
27+
const PROBABLY_A_DIRECTORY_RE = /^[^.]+$/;
2928

3029
// RE to match the markdown files that are extracted from the README.md
3130
const GENERATED_MARKDOWN_RE = /^\d+-.*\.md$/;
@@ -59,7 +58,7 @@ const promptYN = () => new Promise( ( resolve, reject ) => {
5958
* @param {string} inputDir The file system path to the directory to read
6059
* @returns {Promise} A promise to the string array of file names
6160
*/
62-
const ls = ( inputDir, absolute ) => {
61+
const ls = ( inputDir ) => {
6362
return new Promise( ( resolve, reject ) => {
6463
fs.readdir( inputDir, ( err, list ) => {
6564
if ( err ) {
@@ -95,11 +94,11 @@ const runCommand = ( commandStr, otherArgs ) => {
9594
stdio: 'inherit',
9695
} );
9796

98-
spawnedCommand.on( 'error', err => {
97+
spawnedCommand.on( 'error', ( err ) => {
9998
reject( err );
10099
} );
101100

102-
spawnedCommand.on( 'close', code => {
101+
spawnedCommand.on( 'close', ( code ) => {
103102
return code ? reject( code ) : resolve();
104103
} );
105104
} );
@@ -113,7 +112,7 @@ const runCommand = ( commandStr, otherArgs ) => {
113112
* @returns {Promise} A promise that will resolve once all the promises
114113
* returned by that function successfully complete
115114
*/
116-
const runInSequence = arrOfFnsReturningPromises => {
115+
const runInSequence = ( arrOfFnsReturningPromises ) => {
117116
return arrOfFnsReturningPromises.reduce(
118117
( lastStep, startNextStep ) => lastStep.then( startNextStep ),
119118
Promise.resolve()
@@ -132,7 +131,7 @@ runCommand( 'rm -rf docs-tmp' )
132131
console.log( 'By proceeding, you affirm that this is not going to ruin anybody\'s day.' );
133132
console.log( '\nContinue?' );
134133

135-
return promptYN().then( result => {
134+
return promptYN().then( ( result ) => {
136135
if ( result ) {
137136
console.log( '\nGreat, let\'s get this show on the road...' );
138137
resolve();
@@ -155,7 +154,7 @@ runCommand( 'rm -rf docs-tmp' )
155154
// Remove auto-generated files from the root of the gh-pages branch, in case
156155
// file names have changed since the last deploy
157156
.then( () => ls( projectRoot )
158-
.then( files => {
157+
.then( ( files ) => {
159158
const removeFiles = files
160159
.filter( file => GENERATED_MARKDOWN_RE.test( file ) )
161160
.map( file => () => runCommand( `rm ${file}` ) );
@@ -169,12 +168,12 @@ runCommand( 'rm -rf docs-tmp' )
169168
// Filter out unneeded files from the list
170169
.then( fileList => fileList.filter( result => ! OMIT_FILE_RE.test( result ) ) )
171170
// Copy things from the temp directory down into the directory root
172-
.then( fileList => {
171+
.then( ( fileList ) => {
173172
// Create an array of functions that each remove a directory in the root of
174173
// this project which could block the success of the `mv` command below
175174
const removeDirectories = fileList
176175
.filter( file => PROBABLY_A_DIRECTORY_RE.test( file ) )
177-
.map( dir => {
176+
.map( ( dir ) => {
178177
// Ignore errors b/c they will usually be nothing more than a warning
179178
// that a file we tried to delete didn't exist to begin with
180179
return () => runCommand( `rm -rf ${dir}` ).catch( err => console.log( err ) );
@@ -183,8 +182,8 @@ runCommand( 'rm -rf docs-tmp' )
183182
return runInSequence( removeDirectories ).then( () => fileList );
184183
} )
185184
// Copy files over
186-
.then( fileList => {
187-
const copyFiles = fileList.map( file => {
185+
.then( ( fileList ) => {
186+
const copyFiles = fileList.map( ( file ) => {
188187
return () => runCommand( `mv docs-tmp/${file} ./${file}` );
189188
} );
190189
return runInSequence( copyFiles ).then( () => fileList );
@@ -196,10 +195,10 @@ runCommand( 'rm -rf docs-tmp' )
196195
// have not changed but a new .zip is generated with the same contents, Git
197196
// will still regard it as an updated file and too many of those could bloat
198197
// the repo. Easier to exclude it for docs-only updates.
199-
.then( () => new Promise( ( resolve, reject ) => {
198+
.then( () => new Promise( ( resolve ) => {
200199
console.log( '\nHas the wpapi.zip bundle changed since last deploy? (If unsure, answer "Yes")' );
201200

202-
return promptYN().then( result => {
201+
return promptYN().then( ( result ) => {
203202
if ( result ) {
204203
console.log( 'Including updated wpapi.zip in build...' );
205204
resolve();
@@ -215,7 +214,7 @@ runCommand( 'rm -rf docs-tmp' )
215214
.then( () => new Promise( ( resolve, reject ) => {
216215
console.log( '\nDocumentation staged for commit. Proceed with commit & push?' );
217216

218-
return promptYN().then( result => {
217+
return promptYN().then( ( result ) => {
219218
if ( result ) {
220219
console.log( '\nConfirmed, committing & pushing docs branch...' );
221220
resolve();

lib/data/.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
'rules': {
3+
'no-console': [ 'off' ],
4+
},
5+
};

lib/data/update-default-routes-json.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#!/bin/sh
2-
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"
3-
// ^^^ Lovely polyglot script to permit usage via node _or_ via bash: see
4-
// http://unix.stackexchange.com/questions/65235/universal-node-js-shebang
5-
61
/**
72
* To avoid requiring that auto-discovery be utilized every time the API client
83
* is initialized, this library ships with a built-in route definition from a
@@ -65,7 +60,6 @@
6560
* application's directory. The name of the output file can be customized with
6661
* the `--file` option.
6762
*/
68-
/* eslint-disable no-console */
6963
'use strict';
7064

7165
var agent = require( 'superagent' );

webpack.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ module.exports = {
1717

1818
module: {
1919
loaders: [
20-
{ test: /\.json$/, loader: 'json-loader' },
20+
{
21+
test: /\.json$/,
22+
loader: 'json-loader',
23+
},
2124
],
2225
},
2326
};

0 commit comments

Comments
 (0)