Skip to content

Commit 0eb51df

Browse files
committed
Switch to arrow functions where appropriate
1 parent 7d81ec6 commit 0eb51df

File tree

7 files changed

+69
-68
lines changed

7 files changed

+69
-68
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"extends": "plugin:@wordpress/eslint-plugin/recommended",
77
"rules": {
8-
"one-var": ["error", "never"]
8+
"one-var": ["error", "never"],
9+
"prefer-arrow-callback": ["error"]
910
}
1011
}

lib/patch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
let ab = false;
99
try {
1010
diff = diff.split( '\n' );
11-
_.each( diff, function( line ) {
11+
_.each( diff, ( line ) => {
1212
if ( _.startsWith( line, 'diff --git a/' ) ) {
1313
throw true;
1414
}
@@ -52,7 +52,7 @@ module.exports = {
5252

5353
try {
5454
diff = diff.split( '\n' );
55-
_.each( diff, function( line ) {
55+
_.each( diff, ( line ) => {
5656
// these are often the first line
5757
if ( _.startsWith( line, 'Index: src/' ) ||
5858
_.startsWith( line, 'Index: tests/' ) ||
@@ -68,7 +68,7 @@ module.exports = {
6868
throw false;
6969
}
7070

71-
_.each( wpDashExceptions, function( exception ) {
71+
_.each( wpDashExceptions, ( exception ) => {
7272
if ( _.startsWith( line, 'Index: ' + exception ) ||
7373
_.startsWith( line, 'diff --git ' + exception ) ||
7474
_.startsWith( line, 'diff --git a/' + exception )
@@ -77,7 +77,7 @@ module.exports = {
7777
}
7878
} );
7979

80-
_.each( noWpDashExceptions, function( exception ) {
80+
_.each( noWpDashExceptions, ( exception ) => {
8181
if ( _.startsWith( line, 'Index: ' + exception ) ||
8282
_.startsWith( line, 'diff --git ' + exception ) ||
8383
_.startsWith( line, 'diff --git a/' + exception )

lib/regex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
return html.match( /<dt([\s|\S]*?)dt>/g );
1515
},
1616
possiblePatches( longMatches ) {
17-
return _.compact( _.map( longMatches, function( match ) {
17+
return _.compact( _.map( longMatches, ( match ) => {
1818
if ( match.match( /(patch|diff)"/ ) ) {
1919
return _.clean( _.trim( _( match ).stripTags().replace( /\n/g, ' ' ) ) );
2020
}

tasks/patch_wordpress.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = function( grunt ) {
4343
const parsedUrl = url.parse( patchUrl );
4444

4545
// What to do when either our patch is ready
46-
grunt.event.once( 'fileReady', function( level, moveToSrc ) {
46+
grunt.event.once( 'fileReady', ( level, moveToSrc ) => {
4747
const patchOptions = {};
4848
const patchArgs = [];
4949

@@ -72,7 +72,7 @@ module.exports = function( grunt ) {
7272

7373
const patchProcess = spawn( 'patch', patchArgs, patchOptions );
7474

75-
patchProcess.on( 'exit', function( code, signal ) {
75+
patchProcess.on( 'exit', ( code, signal ) => {
7676
if ( signal ) {
7777
grunt.log.debug( 'error signal: ' + signal );
7878
}
@@ -89,7 +89,7 @@ module.exports = function( grunt ) {
8989
} );
9090

9191
// or we know we have failed
92-
grunt.event.once( 'fileFail', function( msg ) {
92+
grunt.event.once( 'fileFail', ( msg ) => {
9393
if ( 'string' === typeof msg ) {
9494
grunt.log.errorlns( msg );
9595
}
@@ -143,7 +143,7 @@ module.exports = function( grunt ) {
143143
let possiblePatches;
144144

145145
grunt.log.debug( 'getPatchFromTicket: ' + patchUrl );
146-
request( patchUrl, function( error, response, body ) {
146+
request( patchUrl, ( error, response, body ) => {
147147
if ( ! error && 200 === response.statusCode ) {
148148
matches = regex.patchAttachments( body );
149149
grunt.log.debug( 'matches: ' + JSON.stringify( matches ) );
@@ -195,7 +195,7 @@ module.exports = function( grunt ) {
195195

196196
function getPatch( patchUrl ) {
197197
grunt.log.debug( 'getting patch: ' + patchUrl );
198-
request( patchUrl, function( error, response, body ) {
198+
request( patchUrl, ( error, response, body ) => {
199199
if ( ! error && 200 === response.statusCode ) {
200200
const level = patch.isAb( body ) ? 1 : 0;
201201
const moveToSrc = patch.moveToSrc( body );
@@ -233,7 +233,7 @@ module.exports = function( grunt ) {
233233

234234
function localFile( error, result, code, done, options ) {
235235
if ( ! error ) {
236-
const files = _.filter( result.split( '\n' ), function( file ) {
236+
const files = _.filter( result.split( '\n' ), ( file ) => {
237237
return ( _.str.include( file, 'patch' ) || _.str.include( file, 'diff' ) );
238238
} );
239239
grunt.log.debug( 'files: ' + JSON.stringify( files ) );
@@ -278,7 +278,7 @@ module.exports = function( grunt ) {
278278

279279
const fileFinderCommand = isSvn() ? 'svn status ' : 'git ls-files --other --exclude-standard';
280280

281-
exec( fileFinderCommand, function( error, result, code ) {
281+
exec( fileFinderCommand, ( error, result, code ) => {
282282
localFile( error, result, code, done, options );
283283
} );
284284
} else {
@@ -301,7 +301,7 @@ module.exports = function( grunt ) {
301301
const uploadPatchWithCredentials = function( username, password ) {
302302
const diffCommand = isSvn() ? 'svn diff --diff-cmd diff' : 'git diff';
303303

304-
exec( diffCommand, function( error, result ) {
304+
exec( diffCommand, ( error, result ) => {
305305
const client = xmlrpc.createSecureClient( {
306306
hostname: options.tracUrl,
307307
port: 443,
@@ -319,7 +319,7 @@ module.exports = function( grunt ) {
319319
'', // description. empty for now.
320320
new Buffer( new Buffer( result ).toString( 'base64' ), 'base64' ),
321321
false, // never overwrite the old file
322-
], function( err ) {
322+
], ( err ) => {
323323
if ( null === err ) {
324324
grunt.log.writeln( 'Uploaded patch.' );
325325
done();

test/patch_wordpress_test.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,157 +6,157 @@ const url = require( 'url' );
66
const trac = require( '../lib/trac.js' );
77
const mapOldToNewFilePath = require( '../lib/map_old_to_new_file_path.js' );
88

9-
describe( 'grunt_patch_wordpress', function() {
10-
describe( 'sanity checks', function() {
11-
it( 'a is a', function() {
9+
describe( 'grunt_patch_wordpress', () => {
10+
describe( 'sanity checks', () => {
11+
it( 'a is a', () => {
1212
expect( 'a' ).toEqual( 'a' );
1313
} );
1414
} );
1515

16-
it( 'convertToRaw converts urls', function() {
16+
it( 'convertToRaw converts urls', () => {
1717
expect( trac.convertToRaw( url.parse( 'https://core.trac.wordpress.org/attachment/ticket/26700/26700.diff' ) ) ).toEqual( 'https://core.trac.wordpress.org/raw-attachment/ticket/26700/26700.diff' );
1818
} );
1919

20-
describe( 'Level Calculator', function() {
20+
describe( 'Level Calculator', () => {
2121
// @TODO: Find alot of patches to use here
2222

23-
it( '26602.2.diff is 0', function() {
23+
it( '26602.2.diff is 0', () => {
2424
const file = grunt.file.read( 'test/fixtures/26602.2.diff' );
2525
expect( patch.isAb( file ) ).toBe( false );
2626
} );
2727
} );
2828

29-
describe( 'mapOldToNewFilePath', function() {
29+
describe( 'mapOldToNewFilePath', () => {
3030
const fileMappings = {
3131
'src/wp-admin/js/color-picker.js': 'src/js/_enqueues/lib/color-picker.js',
3232
'wp-admin/js/color-picker.js': 'js/_enqueues/lib/color-picker.js',
3333
};
3434

35-
describe( 'old to new', function() {
36-
beforeAll( function() {
35+
describe( 'old to new', () => {
36+
beforeAll( () => {
3737
grunt.file.copy( './test/fixtures/patch_wordpress_1.diff', './test/tmp/patch_wordpress_1_copy.diff' );
3838
mapOldToNewFilePath( './test/tmp/patch_wordpress_1_copy.diff', fileMappings );
3939
} );
4040

41-
it( 'replaces old file paths with new file paths in the diff', function() {
41+
it( 'replaces old file paths with new file paths in the diff', () => {
4242
const expected = grunt.file.read( './test/expected/patch_wordpress_1.diff' );
4343
const actual = grunt.file.read( './test/tmp/patch_wordpress_1_copy.diff' );
4444

4545
expect( actual ).toEqual( expected );
4646
} );
4747

48-
afterAll( function() {
48+
afterAll( () => {
4949
grunt.file.delete( './test/tmp/patch_wordpress_1_copy.diff' );
5050
} );
5151
} );
5252

53-
describe( 'new stay unchanged', function() {
54-
beforeAll( function() {
53+
describe( 'new stay unchanged', () => {
54+
beforeAll( () => {
5555
grunt.file.copy( './test/fixtures/patch_wordpress_2.diff', './test/tmp/patch_wordpress_2_copy.diff' );
5656
mapOldToNewFilePath( './test/tmp/patch_wordpress_2_copy.diff', fileMappings );
5757
} );
5858

59-
it( 'doesn\'t replace new file paths', function() {
59+
it( 'doesn\'t replace new file paths', () => {
6060
const expected = grunt.file.read( './test/expected/patch_wordpress_2.diff' );
6161
const actual = grunt.file.read( './test/tmp/patch_wordpress_2_copy.diff' );
6262

6363
expect( actual ).toEqual( expected );
6464
} );
6565

66-
afterAll( function() {
66+
afterAll( () => {
6767
grunt.file.delete( './test/tmp/patch_wordpress_2_copy.diff' );
6868
} );
6969
} );
7070

71-
describe( 'unknown stay unchanged', function() {
72-
beforeAll( function() {
71+
describe( 'unknown stay unchanged', () => {
72+
beforeAll( () => {
7373
grunt.file.copy( './test/fixtures/patch_wordpress_3.diff', './test/tmp/patch_wordpress_3_copy.diff' );
7474
mapOldToNewFilePath( './test/tmp/patch_wordpress_3_copy.diff', fileMappings );
7575
} );
7676

77-
it( 'doesn\'t replace file paths that are not in the file mappings object', function() {
77+
it( 'doesn\'t replace file paths that are not in the file mappings object', () => {
7878
const expected = grunt.file.read( './test/expected/patch_wordpress_3.diff' );
7979
const actual = grunt.file.read( './test/tmp/patch_wordpress_3_copy.diff' );
8080

8181
expect( actual ).toEqual( expected );
8282
} );
8383

84-
afterAll( function() {
84+
afterAll( () => {
8585
grunt.file.delete( './test/tmp/patch_wordpress_3_copy.diff' );
8686
} );
8787
} );
8888

89-
describe( 'new stay unchanged, old to new', function() {
90-
beforeAll( function() {
89+
describe( 'new stay unchanged, old to new', () => {
90+
beforeAll( () => {
9191
grunt.file.copy( './test/fixtures/patch_wordpress_4.diff', './test/tmp/patch_wordpress_4_copy.diff' );
9292
mapOldToNewFilePath( './test/tmp/patch_wordpress_4_copy.diff', fileMappings );
9393
} );
9494

9595
it( 'replaces old file paths with new file paths but doesn\'t replace file paths that are not ' +
96-
'in the file mappings object in a diff file with multiple diffs', function() {
96+
'in the file mappings object in a diff file with multiple diffs', () => {
9797
const expected = grunt.file.read( './test/expected/patch_wordpress_4.diff' );
9898
const actual = grunt.file.read( './test/tmp/patch_wordpress_4_copy.diff' );
9999

100100
expect( actual ).toEqual( expected );
101101
} );
102102

103-
afterAll( function() {
103+
afterAll( () => {
104104
grunt.file.delete( './test/tmp/patch_wordpress_4_copy.diff' );
105105
} );
106106
} );
107107

108-
describe( 'new and unknown stay unchanged', function() {
109-
beforeAll( function() {
108+
describe( 'new and unknown stay unchanged', () => {
109+
beforeAll( () => {
110110
grunt.file.copy( './test/fixtures/patch_wordpress_5.diff', './test/tmp/patch_wordpress_5_copy.diff' );
111111
mapOldToNewFilePath( './test/tmp/patch_wordpress_5_copy.diff', fileMappings );
112112
} );
113113

114114
it( 'doesn\'t replaces new file paths and file paths that are not in the file mappings object in a diff file' +
115-
' with multiple diffs', function() {
115+
' with multiple diffs', () => {
116116
const expected = grunt.file.read( './test/expected/patch_wordpress_5.diff' );
117117
const actual = grunt.file.read( './test/tmp/patch_wordpress_5_copy.diff' );
118118

119119
expect( actual ).toEqual( expected );
120120
} );
121121

122-
afterAll( function() {
122+
afterAll( () => {
123123
grunt.file.delete( './test/tmp/patch_wordpress_5_copy.diff' );
124124
} );
125125
} );
126126

127-
describe( 'new and unknown stay unchanged, old to new', function() {
128-
beforeAll( function() {
127+
describe( 'new and unknown stay unchanged, old to new', () => {
128+
beforeAll( () => {
129129
grunt.file.copy( './test/fixtures/patch_wordpress_6.diff', './test/tmp/patch_wordpress_6_copy.diff' );
130130
mapOldToNewFilePath( './test/tmp/patch_wordpress_6_copy.diff', fileMappings );
131131
} );
132132

133-
it( 'only replaces old file paths in a diff file with multiple diffs', function() {
133+
it( 'only replaces old file paths in a diff file with multiple diffs', () => {
134134
const expected = grunt.file.read( './test/expected/patch_wordpress_6.diff' );
135135
const actual = grunt.file.read( './test/tmp/patch_wordpress_6_copy.diff' );
136136

137137
expect( actual ).toEqual( expected );
138138
} );
139139

140-
afterAll( function() {
140+
afterAll( () => {
141141
grunt.file.delete( './test/tmp/patch_wordpress_6_copy.diff' );
142142
} );
143143
} );
144144

145145
// There is no src folder in core.
146-
describe( 'non-src old to new', function() {
147-
beforeAll( function() {
146+
describe( 'non-src old to new', () => {
147+
beforeAll( () => {
148148
grunt.file.copy( './test/fixtures/patch_wordpress_7.diff', './test/tmp/patch_wordpress_7_copy.diff' );
149149
mapOldToNewFilePath( './test/tmp/patch_wordpress_7_copy.diff', fileMappings );
150150
} );
151151

152-
it( 'replaces old file paths with new file paths in a diff with non-src file paths', function() {
152+
it( 'replaces old file paths with new file paths in a diff with non-src file paths', () => {
153153
const expected = grunt.file.read( './test/expected/patch_wordpress_7.diff' );
154154
const actual = grunt.file.read( './test/tmp/patch_wordpress_7_copy.diff' );
155155

156156
expect( actual ).toEqual( expected );
157157
} );
158158

159-
afterAll( function() {
159+
afterAll( () => {
160160
grunt.file.delete( './test/tmp/patch_wordpress_7_copy.diff' );
161161
} );
162162
} );

test/patches.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,54 @@ const testsGit = grunt.file.read( 'test/fixtures/tests.develop.git.diff' );
1515
const abyes = grunt.file.read( 'test/fixtures/git.diff.ab.diff' );
1616
const coreTrunkSvn = grunt.file.read( 'test/fixtures/core.svn.trunk.diff' );
1717

18-
describe( 'Patch helpers', function() {
19-
it( 'git a/b diffs should not automatticaly trigger moving to src', function() {
18+
describe( 'Patch helpers', () => {
19+
it( 'git a/b diffs should not automatticaly trigger moving to src', () => {
2020
expect( patch.moveToSrc( abyes ) ).not.toBe( true );
2121
} );
2222

23-
it( 'tests diffs should always be applied in the root of the checkout', function() {
23+
it( 'tests diffs should always be applied in the root of the checkout', () => {
2424
expect( patch.moveToSrc( testsGit ) ).not.toBe( true );
2525
expect( patch.moveToSrc( testsSvn ) ).not.toBe( true );
2626
} );
2727

28-
it( 'dev.git diffs should always be applied in the root of the checkout', function() {
28+
it( 'dev.git diffs should always be applied in the root of the checkout', () => {
2929
expect( patch.moveToSrc( developGit ) ).not.toBe( true );
3030
expect( patch.moveToSrc( developIndexGit ) ).not.toBe( true );
3131
} );
3232

33-
it( 'dev.svn diffs should always be applied in the root of the checkout', function() {
33+
it( 'dev.svn diffs should always be applied in the root of the checkout', () => {
3434
expect( patch.moveToSrc( developSvn ) ).not.toBe( true );
3535
expect( patch.moveToSrc( developIndexSvn ) ).not.toBe( true );
3636
} );
3737

38-
it( 'core.git.wordpress.org diffs should always be applied in the svn folder', function() {
38+
it( 'core.git.wordpress.org diffs should always be applied in the svn folder', () => {
3939
expect( patch.moveToSrc( coreGit ) ).toBe( true );
4040
} );
4141

42-
it( 'core.svn.wordpress.org diffs should always be applied in the svn folder', function() {
42+
it( 'core.svn.wordpress.org diffs should always be applied in the svn folder', () => {
4343
expect( patch.moveToSrc( coreSvn ) ).toBe( true );
4444
} );
4545

46-
it( 'core.svn.wordpress.org diffs from trunk should always be applied in the src folder', function() {
46+
it( 'core.svn.wordpress.org diffs from trunk should always be applied in the src folder', () => {
4747
expect( patch.moveToSrc( coreTrunkSvn ) ).toBe( true );
4848
expect( patch.isAb( coreTrunkSvn ) ).toBe( true );
4949
} );
5050

51-
it( 'index.php should always be applied in the src folder', function() {
51+
it( 'index.php should always be applied in the src folder', () => {
5252
expect( patch.moveToSrc( coreIndexSvn ) ).toBe( true );
5353
expect( patch.moveToSrc( coreIndexGit ) ).toBe( true );
5454
} );
5555

56-
it( 'wp-config-sample.php should always be applied in the root folder', function() {
56+
it( 'wp-config-sample.php should always be applied in the root folder', () => {
5757
expect( patch.moveToSrc( developSampleSvn ) ).not.toBe( true );
5858
expect( patch.moveToSrc( developSampleGit ) ).not.toBe( true );
5959
} );
6060

61-
it( 'isAb should return true on patches with a/ b/ style', function() {
61+
it( 'isAb should return true on patches with a/ b/ style', () => {
6262
expect( patch.isAb( abyes ) ).toBe( true );
6363
} );
6464

65-
it( 'isAb should return false on patches without a/ b/ style', function() {
65+
it( 'isAb should return false on patches without a/ b/ style', () => {
6666
expect( patch.isAb( developSampleGit ) ).not.toBe( true );
6767
expect( patch.isAb( developSampleSvn ) ).not.toBe( true );
6868
expect( patch.isAb( coreIndexGit ) ).not.toBe( true );

0 commit comments

Comments
 (0)