mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Custom ESLint rules to enforce new ThemedComponent selector convention
The following cases are covered: - ThemedComponent wrapper selectors must not start with ds-themed- - Base component selectors must start with ds-base- - Themed component selectors must start with ds-themed- - The ThemedComponent wrapper must always be used in HTML - The ThemedComponent wrapper must be used in TypeScript _where appropriate_: - Required - Explicit usages (e.g. modal instantiation, routing modules, ...) - By.css selector queries (in order to align with the HTML rule) - Unchecked - Non-routing modules (to ensure the components can be declared) - ViewChild hooks (since they need to attach to the underlying component) All rules work with --fix to automatically migrate to the new convention This covers most of the codebase, but minor manual adjustment are needed afterwards
This commit is contained in:
52
lint/test/testing.ts
Normal file
52
lint/test/testing.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
||||
import { RuleTester } from 'eslint';
|
||||
import { RuleTester as TypeScriptRuleTester } from '@typescript-eslint/rule-tester';
|
||||
import { themeableComponents } from '../src/util/theme-support';
|
||||
|
||||
const FIXTURE = 'lint/test/fixture/';
|
||||
|
||||
// Register themed components from test fixture
|
||||
themeableComponents.initialize(FIXTURE);
|
||||
|
||||
TypeScriptRuleTester.itOnly = fit;
|
||||
|
||||
export function fixture(path: string): string {
|
||||
return FIXTURE + path;
|
||||
}
|
||||
|
||||
export const tsRuleTester = new TypeScriptRuleTester({
|
||||
parser: '@typescript-eslint/parser',
|
||||
defaultFilenames: {
|
||||
ts: fixture('src/test.ts'),
|
||||
tsx: 'n/a',
|
||||
},
|
||||
parserOptions: {
|
||||
project: fixture('tsconfig.json'),
|
||||
}
|
||||
});
|
||||
|
||||
class HtmlRuleTester extends RuleTester {
|
||||
run(name: string, rule: any, tests: { valid: any[], invalid: any[] }) {
|
||||
super.run(name, rule, {
|
||||
valid: tests.valid.map((test) => ({
|
||||
filename: fixture('test.html'),
|
||||
...test,
|
||||
})),
|
||||
invalid: tests.invalid.map((test) => ({
|
||||
filename: fixture('test.html'),
|
||||
...test,
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const htmlRuleTester = new HtmlRuleTester({
|
||||
parser: require.resolve('@angular-eslint/template-parser'),
|
||||
});
|
Reference in New Issue
Block a user