Skip to content

Commit 0fd1a16

Browse files
authored
Merge pull request #2006 from WordPress/dependabot/npm_and_yarn/lint-staged-16.0.0
Bump lint-staged from 15.5.1 to 16.0.0
2 parents 900b6e7 + 2b604a4 commit 0fd1a16

File tree

6 files changed

+104
-214
lines changed

6 files changed

+104
-214
lines changed

lint-staged.config.js

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,32 @@
11
/**
22
* External dependencies
33
*/
4-
const path = require( 'path' );
5-
const micromatch = require( 'micromatch' );
4+
const fs = require( 'fs' );
65

76
/**
87
* Internal dependencies
98
*/
109
const { plugins } = require( './plugins.json' );
1110

1211
/**
13-
* Join and escape filenames for shell.
14-
*
15-
* @param {string[]} files Files to join.
16-
*
17-
* @return {string} Joined files.
12+
* @type {import('lint-staged').Configuration}
1813
*/
19-
const joinFiles = ( files ) => {
20-
return files.map( ( file ) => `'${ file }'` ).join( ' ' );
14+
const config = {
15+
'**/*.{js,ts,mjs}': [ 'npm run lint-js', () => 'npm run tsc' ],
16+
'**/*.php': () => 'composer phpstan',
17+
'*.php': 'composer lint',
18+
'/tools/**.php': 'composer lint',
19+
// Note: Instead of the preceding two lines, the following line was tried but it is not working:
20+
// [ `!(plugins/{${ plugins.join( '|' ) }})/**/*.php` ]: 'composer lint',
2121
};
2222

23-
// Get plugin base name to match regex more accurately.
24-
// Else it can cause issues when this plugin is placed in `wp-content/plugins` directory.
25-
const PLUGIN_BASE_NAME = path.basename( __dirname );
23+
for ( const plugin of plugins ) {
24+
const phpcsConfig = fs.existsSync( `plugins/${ plugin }/phpcs.xml` )
25+
? `plugins/${ plugin }/phpcs.xml`
26+
: `plugins/${ plugin }/phpcs.xml.dist`;
27+
config[
28+
`plugins/${ plugin }/**/*.php`
29+
] = `composer lint -- --standard=${ phpcsConfig }`;
30+
}
2631

27-
module.exports = {
28-
'**/*.{js,ts}': ( files ) => {
29-
return [ `npm run lint-js -- ${ joinFiles( files ) }`, `npm run tsc` ];
30-
},
31-
'**/*.php': ( files ) => {
32-
const commands = [ 'composer phpstan' ];
33-
34-
plugins.forEach( ( plugin ) => {
35-
const pluginFiles = micromatch(
36-
files,
37-
`**/${ PLUGIN_BASE_NAME }/plugins/${ plugin }/**`,
38-
{ dot: true }
39-
);
40-
41-
if ( pluginFiles.length ) {
42-
// Note: The lint command has to be used directly because the plugin-specific lint command includes the entire plugin directory as an argument.
43-
commands.push(
44-
`composer lint -- --standard=./plugins/${ plugin }/phpcs.xml.dist ${ joinFiles(
45-
pluginFiles
46-
) }`
47-
);
48-
}
49-
} );
50-
51-
const otherFiles = micromatch(
52-
files,
53-
`!**/${ PLUGIN_BASE_NAME }/plugins/**`,
54-
{ dot: true }
55-
);
56-
57-
if ( otherFiles.length ) {
58-
commands.push( `composer lint -- ${ joinFiles( otherFiles ) }` );
59-
}
60-
61-
return commands;
62-
},
63-
};
32+
module.exports = config;

0 commit comments

Comments
 (0)