Skip to content

Commit e86895f

Browse files
authored
Merge pull request #72 from kadamwhite/update-coding-standards
Switch to @wordpress/eslint-plugin/recommended standards
2 parents b2b4b53 + 0eb51df commit e86895f

File tree

12 files changed

+337
-364
lines changed

12 files changed

+337
-364
lines changed

.eslintrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": "plugin:@wordpress/eslint-plugin/recommended",
7+
"rules": {
8+
"one-var": ["error", "never"],
9+
"prefer-arrow-callback": ["error"]
10+
}
11+
}

.eslintrc.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/map_old_to_new_file_path.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
var grunt = require( 'grunt' );
1+
const grunt = require( 'grunt' );
22

33
/**
44
* Replaces file names in the passed filePath with the file names in the fileMappings.
55
*
6-
* @param filePath The path to the file where the filenames should be replaced.
7-
* @param fileMappings The file names to replace and the file names they should be replaced with.
6+
* @param {string} filePath The path to the file where the filenames should be replaced.
7+
* @param {Object} fileMappings The file names to replace and the file names they should be replaced with.
88
*
9-
* @returns {void}
9+
* @return {void}
1010
*/
1111
function mapOldToNewFilePath( filePath, fileMappings ) {
12-
var body = grunt.file.read( filePath ),
13-
newBody,
14-
oldPath;
12+
const body = grunt.file.read( filePath );
13+
let newBody;
14+
let oldPath;
1515
for ( oldPath in fileMappings ) {
16-
1716
// Ensure only own properties are looped over.
1817
if ( ! fileMappings.hasOwnProperty( oldPath ) ) {
1918
continue;

lib/patch.js

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
var grunt = require( 'grunt' ),
2-
_ = require( 'underscore' );
1+
const _ = require( 'underscore' );
32

43
_.str = _.str = require( 'underscore.string' );
54
_.mixin( _.str.exports() );
65

76
module.exports = {
8-
isAb: function( diff ) {
9-
var ab = false;
7+
isAb( diff ) {
8+
let ab = false;
109
try {
1110
diff = diff.split( '\n' );
12-
_.each( diff, function( line ) {
11+
_.each( diff, ( line ) => {
1312
if ( _.startsWith( line, 'diff --git a/' ) ) {
1413
throw true;
1514
}
1615
if ( _.startsWith( line, 'Index: trunk/wp-' ) ) {
1716
throw true;
1817
}
19-
});
18+
} );
2019
} catch ( e ) {
2120
ab = e;
2221
}
@@ -25,83 +24,81 @@ module.exports = {
2524
},
2625

2726
/**
28-
Check to see if we should apply the diff from the src dir
29-
30-
@returns bool true if we should go into src to apply the diff
31-
*/
32-
moveToSrc: function( diff ) {
33-
var src = false,
34-
wpDashExceptions = [
35-
'.editorconfig',
36-
'.gitignore',
37-
'.jshintrc',
38-
'.travis.yml',
39-
'Gruntfile.js',
40-
'package.json',
41-
'phpunit.xml.dist',
42-
'wp-cli.yml',
43-
'wp-config-sample.php',
44-
'wp-tests-config-sample.php'
45-
],
46-
noWpDashExceptions = [
47-
'index.php',
48-
'license.txt',
49-
'readme.html',
50-
'xmlrpc.php'
51-
];
27+
* Check to see if we should apply the diff from the src dir
28+
*
29+
* @param {string} diff A string diff
30+
* @return {boolean} true if we should go into src to apply the diff
31+
*/
32+
moveToSrc( diff ) {
33+
let src = false;
34+
const wpDashExceptions = [
35+
'.editorconfig',
36+
'.gitignore',
37+
'.jshintrc',
38+
'.travis.yml',
39+
'Gruntfile.js',
40+
'package.json',
41+
'phpunit.xml.dist',
42+
'wp-cli.yml',
43+
'wp-config-sample.php',
44+
'wp-tests-config-sample.php',
45+
];
46+
const noWpDashExceptions = [
47+
'index.php',
48+
'license.txt',
49+
'readme.html',
50+
'xmlrpc.php',
51+
];
5252

5353
try {
5454
diff = diff.split( '\n' );
55-
_.each( diff, function( line ) {
56-
55+
_.each( diff, ( line ) => {
5756
// these are often the first line
58-
if ( _.startsWith( line, 'Index: src/' ) ||
59-
_.startsWith( line, 'Index: tests/' ) ||
60-
_.startsWith( line, 'Index: tools/' ) ||
61-
_.startsWith( line, 'diff --git src' ) ||
62-
_.startsWith( line, 'diff --git test' ) ||
63-
_.startsWith( line, 'diff --git tools' ) ||
64-
_.startsWith( line, 'diff --git a/src' ) ||
65-
_.startsWith( line, 'diff --git a/test' ) ||
57+
if ( _.startsWith( line, 'Index: src/' ) ||
58+
_.startsWith( line, 'Index: tests/' ) ||
59+
_.startsWith( line, 'Index: tools/' ) ||
60+
_.startsWith( line, 'diff --git src' ) ||
61+
_.startsWith( line, 'diff --git test' ) ||
62+
_.startsWith( line, 'diff --git tools' ) ||
63+
_.startsWith( line, 'diff --git a/src' ) ||
64+
_.startsWith( line, 'diff --git a/test' ) ||
6665
_.startsWith( line, 'diff --git a/tools' )
6766

6867
) {
6968
throw false;
7069
}
7170

72-
_.each( wpDashExceptions, function( exception ) {
73-
if ( _.startsWith( line, 'Index: ' + exception ) ||
74-
_.startsWith( line, 'diff --git ' + exception ) ||
71+
_.each( wpDashExceptions, ( exception ) => {
72+
if ( _.startsWith( line, 'Index: ' + exception ) ||
73+
_.startsWith( line, 'diff --git ' + exception ) ||
7574
_.startsWith( line, 'diff --git a/' + exception )
7675
) {
7776
throw false;
7877
}
79-
});
78+
} );
8079

81-
_.each( noWpDashExceptions, function( exception ) {
82-
if ( _.startsWith( line, 'Index: ' + exception ) ||
83-
_.startsWith( line, 'diff --git ' + exception ) ||
80+
_.each( noWpDashExceptions, ( exception ) => {
81+
if ( _.startsWith( line, 'Index: ' + exception ) ||
82+
_.startsWith( line, 'diff --git ' + exception ) ||
8483
_.startsWith( line, 'diff --git a/' + exception )
8584
) {
8685
throw true;
8786
}
88-
});
87+
} );
8988

90-
if ( _.startsWith( line, 'Index: wp-' ) ||
89+
if ( _.startsWith( line, 'Index: wp-' ) ||
9190
_.startsWith( line, 'Index: trunk/wp-' ) ||
92-
_.startsWith( line, 'diff --git wp-' ) ||
91+
_.startsWith( line, 'diff --git wp-' ) ||
9392
_.startsWith( line, 'diff --git a/wp-' )
9493
) {
9594
throw true;
9695
}
97-
98-
});
96+
} );
9997
throw true;
10098
} catch ( l ) {
10199
src = l;
102100
}
103101
return src;
104-
}
105-
102+
},
106103

107104
};

lib/regex.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
var _ = require( 'underscore' );
1+
const _ = require( 'underscore' );
22

33
_.str = _.str = require( 'underscore.string' );
44
_.mixin( _.str.exports() );
55

66
module.exports = {
7-
patchAttachments: function( html ) {
7+
patchAttachments( html ) {
88
return html.match( /<dt>\s*<a\s+href="([^"]+?)(diff|patch)"\s+title="View attachment">([^<]+)/g );
99
},
10-
urlsFromAttachmentList: function( html ) {
10+
urlsFromAttachmentList( html ) {
1111
return html.match( /href="([^"]+)"/ );
1212
},
13-
longMatches: function( html ) {
13+
longMatches( html ) {
1414
return html.match( /<dt([\s|\S]*?)dt>/g );
1515
},
16-
possiblePatches: function( longMatches ) {
17-
return _.compact( _.map( longMatches, function( match ) {
16+
possiblePatches( longMatches ) {
17+
return _.compact( _.map( longMatches, ( match ) => {
1818
if ( match.match( /(patch|diff)"/ ) ) {
1919
return _.clean( _.trim( _( match ).stripTags().replace( /\n/g, ' ' ) ) );
20-
} else {
21-
return false;
2220
}
23-
}) );
21+
return false;
22+
} ) );
2423
},
25-
localFileClean: function( file ) {
24+
localFileClean( file ) {
2625
return file.replace( '?', '' ).replace( /\s/g, '' );
27-
}
28-
26+
},
2927

3028
};

lib/trac.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var url = require( 'url' ),
2-
grunt = require( 'grunt' );
1+
const url = require( 'url' );
2+
const grunt = require( 'grunt' );
33

44
module.exports = {
5-
convertToRaw: function( parsedUrl, options ) {
5+
convertToRaw( parsedUrl ) {
66
grunt.log.debug( 'convertToRaw: ' + JSON.stringify( parsedUrl ) );
77
parsedUrl.pathname = parsedUrl.pathname.replace( /attachment/, 'raw-attachment' );
88
grunt.log.debug( 'converted_from_raw: ' + url.format( parsedUrl ) );
99
return url.format( parsedUrl );
10-
}
10+
},
1111

1212
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test": "jest",
2525
"test:coverage": "jest --coverage",
2626
"test:watch": "jest --watch",
27-
"lint": "eslint . --ignore-path coverage",
27+
"lint": "eslint .",
2828
"lint:fix": "eslint . --fix"
2929
},
3030
"jest": {
@@ -33,8 +33,8 @@
3333
]
3434
},
3535
"devDependencies": {
36-
"eslint": "^4.17.0",
37-
"eslint-config-wordpress": "^2.0.0",
36+
"@wordpress/eslint-plugin": "^2.0.0",
37+
"eslint": "^5.15.1",
3838
"jest": "^24.5.0"
3939
},
4040
"dependencies": {

0 commit comments

Comments
 (0)