Skip to content

feat(cli): add declaration-property-value-no-unknown via ng update #1879

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

Merged
merged 1 commit into from
Jan 19, 2025
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: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- [ ] add `declaration-property-value-no-unknown` in `.stylelintrc.js`
-
34 changes: 34 additions & 0 deletions schematics/ng-update/upgrade-rules/V19/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';

import { tryAddFile } from '../../../utils';
import { createAlainApp, migrationCollection } from '../../../utils/testing';

describe('Schematic: ng-update: v19Rule', () => {
let runner: SchematicTestRunner;
let tree: UnitTestTree;
const logs: string[] = [];

beforeEach(async () => {
({ runner, tree } = await createAlainApp());
});

async function runMigration(): Promise<void> {
logs.length = 0;
runner = new SchematicTestRunner('schematics', migrationCollection);
runner.logger.subscribe(e => logs.push(e.message));
await runner.runSchematic('migration-v19', {}, tree);
}

it('add declaration-property-value-no-unknown', async () => {
const filePath = '/.stylelintrc.js';
tryAddFile(
tree,
filePath,
` 'media-query-no-invalid': null,
'order/order': [`
);
await runMigration();
const content = tree.readContent(filePath);
expect(content).toContain(`declaration-property-value-no-unknown`);
});
});
25 changes: 24 additions & 1 deletion schematics/ng-update/upgrade-rules/V19/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { logFinished, logInfo } from '../../../utils';
import { UpgradeMainVersions } from '../../../utils/versions';

function addDPVNU() {
return (tree: Tree) => {
const filePath = '.stylelintrc.js';
const content = tree.read(filePath);
if (!content) {
return;
}
let contentStr = content.toString('utf-8');
if (contentStr.includes('declaration-property-value-no-unknown')) {
return;
}
// 在 'order/order' 之前插入 'declaration-property-value-no-unknown': null,
const findContent = ` 'order/order'`;
const idx = contentStr.indexOf(findContent.trim());
if (idx === -1) {
return;
}
const insertContent = ` 'declaration-property-value-no-unknown': null,\n`;
contentStr = contentStr.replace(findContent, `${insertContent}${findContent}`);
tree.overwrite(filePath, contentStr);
};
}

function finished(): Rule {
return (_tree: Tree, context: SchematicContext) => {
context.addTask(new NodePackageInstallTask());
Expand All @@ -19,6 +42,6 @@ export function v19Rule(): Rule {
return async (tree: Tree, context: SchematicContext) => {
UpgradeMainVersions(tree);
logInfo(context, `Upgrade dependency version number`);
return chain([finished()]);
return chain([addDPVNU(), finished()]);
};
}
4 changes: 2 additions & 2 deletions schematics/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require('source-map-support').install({
const Jasmine = require('jasmine');
const runner = new Jasmine({ projectBaseDir });

// const files = `schematics/**/*.spec.ts`;
const files = `schematics/plugin/plugin.icon.spec.ts`;
const files = `schematics/**/*.spec.ts`;
// const files = `schematics/ng-update/upgrade-rules/V19/index.spec.ts`;

const tests = glob.sync(files).map(p => relative(projectBaseDir, p));

Expand Down
Loading