Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nx-python): add an optional fix option for the ruff-check executor #275

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
51 changes: 51 additions & 0 deletions packages/nx-python/src/executors/ruff-check/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,57 @@ describe('Ruff Check Executor', () => {
expect(output.success).toBe(true);
});

it('should execute ruff check linting', async () => {
vi.mocked(spawn.sync).mockReturnValueOnce({
status: 0,
output: [''],
pid: 0,
signal: null,
stderr: null,
stdout: null,
});

const output = await executor(
{
lintFilePatterns: ['app'],
fix: true,
__unparsed__: [],
},
{
cwd: '',
root: '.',
isVerbose: false,
projectName: 'app',
projectsConfigurations: {
version: 2,
projects: {
app: {
root: 'apps/app',
targets: {},
},
},
},
nxJsonConfiguration: {},
projectGraph: {
dependencies: {},
nodes: {},
},
},
);
expect(checkPrerequisites).toHaveBeenCalled();
expect(spawn.sync).toHaveBeenCalledTimes(1);
expect(spawn.sync).toHaveBeenCalledWith(
'uv',
['run', 'ruff', 'check', 'app', '--fix'],
{
cwd: 'apps/app',
shell: true,
stdio: 'inherit',
},
);
expect(output.success).toBe(true);
});

it('should fail to execute ruff check linting ', async () => {
vi.mocked(spawn.sync).mockReturnValueOnce({
status: 1,
Expand Down
4 changes: 4 additions & 0 deletions packages/nx-python/src/executors/ruff-check/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default async function executor(
.concat(options.lintFilePatterns)
.concat(options.__unparsed__);

if (options.fix) {
commandArgs.push('--fix');
}

const provider = await getProvider(
workspaceRoot,
undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/nx-python/src/executors/ruff-check/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface RuffCheckExecutorSchema {
lintFilePatterns: string[];
fix?: boolean;
__unparsed__: string[];
}
6 changes: 6 additions & 0 deletions packages/nx-python/src/executors/ruff-check/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"type": "string"
}
},
"fix": {
"type": "boolean",
"description": "Fixes linting errors (may overwrite linted files).",
"default": false,
"x-priority": "important"
},
"__unparsed__": {
"hidden": true,
"type": "array",
Expand Down