Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add the `stylelint-scss` dependency, a peer of `@wordpress/stylelint-config` ([#83765](https://github.com/WordPress/gutenberg/pull/83765)).
- `build`, `start` and `lint-pkg-json`: Resolve the default browserslist and npm-package-json-lint configs when dependencies are not hoisted to the project root (npm `install-strategy=linked`, pnpm). `lint-pkg-json` now defaults to `config/npmpackagejsonlint.js`; `config/npmpackagejsonlint.json` stays for projects that reference it ([#83902](https://github.com/WordPress/gutenberg/pull/83902)).
- `lint-js`, `lint-style` and `lint-md-docs`: a file passed right after `--fix` is now treated as a file instead of that flag's value, so only the listed files get processed. Same for `--require-pragma` in `format` ([#83521](https://github.com/WordPress/gutenberg/pull/83521)).

## 36.0.0 (2026-09-23)

Expand Down
14 changes: 13 additions & 1 deletion packages/scripts/utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ const getArgFromCLI = ( arg ) => {

const hasArgInCLI = ( arg ) => getArgFromCLI( arg ) !== undefined;

const getFileArgsFromCLI = () => minimist( getArgsFromCLI() )._;
// Flags that never take a value, so `--fix file.js` isn't read as `--fix=file.js`.
// stylelint's `--fix` does take an optional mode though, so drop that first.
const getFileArgsFromCLI = () => {
const args = getArgsFromCLI().filter(
( arg, index, all ) =>
! (
all[ index - 1 ] === '--fix' &&
[ 'strict', 'lax' ].includes( arg )
)
);

return minimist( args, { boolean: [ 'fix', 'require-pragma' ] } )._;
};

const getNodeArgsFromCLI = () => {
const args = getArgsFromCLI();
Expand Down
34 changes: 34 additions & 0 deletions packages/scripts/utils/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fromConfigRootMock = vi.spyOn( fileUtils, 'fromConfigRoot' );
let crossSpawnMock = vi.spyOn( crossSpawn, 'sync' );
const {
hasArgInCLI,
hasFileArgInCLI,
hasProjectFile,
getWebpackArgs,
spawnScript,
Expand Down Expand Up @@ -66,6 +67,39 @@ describe( 'utils', () => {
} );
} );

describe( 'hasFileArgInCLI', () => {
Comment thread
manzoorwanijk marked this conversation as resolved.
Resolved
afterAll( () => {
getArgsFromCLIMock.mockReset();
} );

test( 'should treat a file after --fix as a file arg', () => {
getArgsFromCLIMock.mockReturnValue( [ '--fix', 'style.scss' ] );

expect( hasFileArgInCLI() ).toBe( true );
} );

test( 'should treat a file after --require-pragma as a file arg', () => {
getArgsFromCLIMock.mockReturnValue( [
'--require-pragma',
'index.js',
] );

expect( hasFileArgInCLI() ).toBe( true );
} );

test( 'should not treat the stylelint --fix mode as a file arg', () => {
getArgsFromCLIMock.mockReturnValue( [ '--fix', 'lax' ] );

expect( hasFileArgInCLI() ).toBe( false );
} );

test( 'should not treat the value of --config as a file arg', () => {
getArgsFromCLIMock.mockReturnValue( [ '--config', 'custom.json' ] );

expect( hasFileArgInCLI() ).toBe( false );
} );
} );

describe( 'hasProjectFile', () => {
test( 'should return false for the current directory and unknown file', () => {
getPackagePathMock.mockReturnValueOnce( currentDirectory );
Expand Down
Loading