Skip to content

Commit

Permalink
fix(schematics): esintFix task to run on NPM correctly (#1667)
Browse files Browse the repository at this point in the history
## Proposed change

Fix EslintFix schematics task to run on NPM correctly

<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that is required for this change. -->

## Related issues

- 🐛 Fixes resolves #1658

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
kpanot committed Apr 23, 2024
2 parents b9b69f5 + 12dc79e commit cf017ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/@o3r/core/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('new otter application', () => {
const execAppOptions = {...getDefaultExecSyncOptions(), cwd: workspacePath};
const relativeProjectPath = path.relative(workspacePath, projectPath);
const projectNameOptions = ['--project-name', projectName];
packageManagerExec({script: 'ng', args: ['add', `@o3r/core@${o3rVersion}`, '--preset', 'all', ...projectNameOptions, '--skip-confirmation']}, execAppOptions);
expect(() => packageManagerExec({ script: 'ng', args: ['add', `@o3r/core@${o3rVersion}`, '--preset', 'all', ...projectNameOptions, '--skip-confirmation'] }, execAppOptions)).not.toThrow();
expect(() => packageManagerInstall(execAppOptions)).not.toThrow();

packageManagerExec({script: 'ng', args: ['g', '@o3r/core:store-entity-async', '--store-name', 'test-entity-async', '--model-name', 'Bound', '--model-id-prop-name', 'id', ...projectNameOptions]},
Expand Down
12 changes: 9 additions & 3 deletions packages/@o3r/schematics/src/rule-factories/eslint-fix/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { DirEntry, noop, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { DirEntry, noop, Rule, SchematicContext, type TaskId, Tree } from '@angular-devkit/schematics';
import { dirname, join } from 'node:path';
import { EslintFixTask, LinterOptions } from '../../tasks/index';

interface ApplyEslintFixOption extends LinterOptions {
/** List of task to wait to run the linter */
dependencyTaskIds?: TaskId[];
}

/**
* Apply EsLint fix
* @param prootPath Root path
* @param _prootPath
* @param extension List of file extensions to lint
* @param options Linter options
*/
export function applyEsLintFix(_prootPath = '/', extension: string[] = ['ts'], options?: LinterOptions): Rule {
export function applyEsLintFix(_prootPath = '/', extension: string[] = ['ts'], options?: ApplyEslintFixOption): Rule {
try {
require.resolve('eslint/package.json');
} catch {
Expand Down Expand Up @@ -71,7 +76,8 @@ You can consider to run later the following command to add otter linter rules: n
undefined,
eslintFile,
linterOptions
)
),
options?.dependencyTaskIds
);
}

Expand Down
14 changes: 13 additions & 1 deletion packages/@o3r/schematics/src/tasks/eslint/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { TaskConfiguration, TaskConfigurationGenerator } from '@angular-devkit/schematics';
import { NodePackageName, NodePackageTaskOptions } from '@angular-devkit/schematics/tasks/package-manager/options';
import { getPackageManager } from '../../utility/package-manager-runner';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import type { WorkspaceSchema } from '../../interfaces';

/**
* Linter options
Expand All @@ -16,19 +18,29 @@ export interface LinterOptions {
* @default true
*/
hideWarnings?: boolean;

/** Workspace configuration file */
workspaceConfig?: WorkspaceSchema;

/** Enforced NPM Package */
enforcedNpmManager?: string;
}

export class EslintFixTask implements TaskConfigurationGenerator<NodePackageTaskOptions> {
export class EslintFixTask extends NodePackageInstallTask implements TaskConfigurationGenerator<NodePackageTaskOptions> {
public linterOptions: LinterOptions;

constructor(public files: string[], public workingDirectory?: string, public configFile?: string, options?: LinterOptions) {
super({
packageManager: getPackageManager(options)
});
this.linterOptions = {
continueOnError: true,
hideWarnings: true,
...options
};
}

/** @inheritdoc */
public toConfiguration(): TaskConfiguration<NodePackageTaskOptions> {
return {
name: NodePackageName,
Expand Down

0 comments on commit cf017ab

Please sign in to comment.