mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Fix lint lint issues
This commit is contained in:
@@ -17,7 +17,7 @@ export default {
|
||||
schema: [],
|
||||
messages: {
|
||||
mustUseThemedWrapperSelector: 'Themeable components should be used via their ThemedComponent wrapper\'s selector',
|
||||
}
|
||||
},
|
||||
},
|
||||
create(context: any) {
|
||||
if (context.getFilename().includes('.spec.ts')) {
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
|
||||
const openTagRange = [
|
||||
node.startSourceSpan.start.offset + 1,
|
||||
node.startSourceSpan.start.offset + 1 + oldSelector.length
|
||||
node.startSourceSpan.start.offset + 1 + oldSelector.length,
|
||||
];
|
||||
|
||||
const ops = [
|
||||
@@ -47,15 +47,15 @@ export default {
|
||||
if (node.startSourceSpan.end.offset !== node.endSourceSpan.end.offset) {
|
||||
const closeTagRange = [
|
||||
node.endSourceSpan.start.offset + 2,
|
||||
node.endSourceSpan.end.offset - 1
|
||||
node.endSourceSpan.end.offset - 1,
|
||||
];
|
||||
ops.push(fixer.replaceTextRange(closeTagRange, newSelector));
|
||||
}
|
||||
|
||||
return ops;
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@@ -6,6 +6,7 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
import { ESLintUtils } from '@typescript-eslint/utils';
|
||||
|
||||
import { getComponentSelectorNode } from '../../util/angular';
|
||||
import { stringLiteral } from '../../util/misc';
|
||||
import {
|
||||
@@ -23,7 +24,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
||||
wrongSelectorUnthemedComponent: 'Unthemed version of themeable components should have a selector starting with \'ds-base-\'',
|
||||
wrongSelectorThemedComponentWrapper: 'Themed component wrapper of themeable components shouldn\'t have a selector starting with \'ds-themed-\'',
|
||||
wrongSelectorThemedComponentOverride: 'Theme override of themeable component should have a selector starting with \'ds-themed-\'',
|
||||
}
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context: any): any {
|
||||
@@ -86,7 +87,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
||||
} else if (isThemeableComponent(className)) {
|
||||
enforceBaseSelector(selectorNode);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@@ -6,6 +6,7 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
import { ESLintUtils } from '@typescript-eslint/utils';
|
||||
|
||||
import { findUsages } from '../../util/misc';
|
||||
import {
|
||||
allThemeableComponents,
|
||||
@@ -50,7 +51,14 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
||||
}
|
||||
|
||||
function handleThemedSelectorQueriesInTests(node: any) {
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
fix(fixer: any){
|
||||
const newSelector = fixSelectors(node.raw);
|
||||
return fixer.replaceText(node, newSelector);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleUnthemedImportsInTypescript(specifierNode: any) {
|
||||
@@ -98,29 +106,11 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
||||
// ignore tests and non-routing modules
|
||||
if (context.getFilename()?.endsWith('.spec.ts')) {
|
||||
return {
|
||||
[`CallExpression[callee.object.name = "By"][callee.property.name = "css"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`](node: any) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
fix(fixer: any){
|
||||
const newSelector = fixSelectors(node.raw);
|
||||
return fixer.replaceText(node, newSelector);
|
||||
}
|
||||
});
|
||||
},
|
||||
[`CallExpression[callee.object.name = "By"][callee.property.name = "css"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`]: handleThemedSelectorQueriesInTests,
|
||||
};
|
||||
} else if (context.getFilename()?.endsWith('.cy.ts')) {
|
||||
return {
|
||||
[`CallExpression[callee.object.name = "cy"][callee.property.name = "get"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`](node: any) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'mustUseThemedWrapper',
|
||||
fix(fixer: any){
|
||||
const newSelector = fixSelectors(node.raw);
|
||||
return fixer.replaceText(node, newSelector);
|
||||
}
|
||||
});
|
||||
},
|
||||
[`CallExpression[callee.object.name = "cy"][callee.property.name = "get"] > Literal:first-child[value = /.*${DISALLOWED_THEME_SELECTORS}.*/]`]: handleThemedSelectorQueriesInTests,
|
||||
};
|
||||
} else if (
|
||||
context.getFilename()?.match(/(?!routing).module.ts$/)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { basename } from 'path';
|
||||
import ts from 'typescript';
|
||||
|
||||
import {
|
||||
isClassDeclaration,
|
||||
isPartOfTypeExpression,
|
||||
@@ -134,7 +135,7 @@ function resolveLocalPath(path: string, relativeTo: string) {
|
||||
const parts = relativeTo.split('/');
|
||||
return [
|
||||
...parts.slice(0, parts.length - 1),
|
||||
path.replace(/^.\//, '')
|
||||
path.replace(/^.\//, ''),
|
||||
].join('/') + '.ts';
|
||||
} else {
|
||||
throw new Error(`Unsupported local path: ${path}`);
|
||||
|
@@ -10,5 +10,5 @@ import { ThemedTestThemeableComponent } from './themed-test-themeable.component'
|
||||
export const ROUTES = [
|
||||
{
|
||||
component: ThemedTestThemeableComponent,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@@ -7,8 +7,9 @@
|
||||
*/
|
||||
// @ts-ignore
|
||||
import { NgModule } from '@angular/core';
|
||||
import { TestThemeableComponent } from './test-themeable.component';
|
||||
|
||||
import { TestComponent } from './test.component';
|
||||
import { TestThemeableComponent } from './test-themeable.component';
|
||||
import { ThemedTestThemeableComponent } from './themed-test-themeable.component';
|
||||
|
||||
@NgModule({
|
||||
@@ -16,7 +17,7 @@ import { ThemedTestThemeableComponent } from './themed-test-themeable.component'
|
||||
TestComponent,
|
||||
TestThemeableComponent,
|
||||
ThemedTestThemeableComponent,
|
||||
]
|
||||
],
|
||||
})
|
||||
export class TestModule {
|
||||
|
||||
|
@@ -6,6 +6,7 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { ThemedComponent } from '../../../../../../src/app/shared/theme-support/themed.component';
|
||||
import { TestThemeableComponent } from './test-themeable.component';
|
||||
|
||||
|
@@ -6,6 +6,7 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { TestThemeableComponent as BaseComponent } from '../../../../app/test/test-themeable.component';
|
||||
|
||||
@Component({
|
||||
|
@@ -7,12 +7,13 @@
|
||||
*/
|
||||
// @ts-ignore
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { TestThemeableComponent } from './app/test/test-themeable.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
TestThemeableComponent,
|
||||
]
|
||||
],
|
||||
})
|
||||
export class TestModule {
|
||||
|
||||
|
@@ -7,11 +7,11 @@
|
||||
*/
|
||||
|
||||
|
||||
import rule from '../../src/rules/ts/themed-component-selectors';
|
||||
import {
|
||||
fixture,
|
||||
tsRuleTester,
|
||||
} from '../testing';
|
||||
import rule from '../../src/rules/ts/themed-component-selectors';
|
||||
|
||||
describe('themed-component-selectors', () => {
|
||||
tsRuleTester.run('themed-component-selectors', rule as any, {
|
||||
|
@@ -6,13 +6,13 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
||||
import htmlRule from '../../src/rules/html/themed-component-usages';
|
||||
import tsRule from '../../src/rules/ts/themed-component-usages';
|
||||
import {
|
||||
fixture,
|
||||
htmlRuleTester,
|
||||
tsRuleTester,
|
||||
} from '../testing';
|
||||
import tsRule from '../../src/rules/ts/themed-component-usages';
|
||||
import htmlRule from '../../src/rules/html/themed-component-usages';
|
||||
|
||||
describe('themed-component-usages (TypeScript)', () => {
|
||||
tsRuleTester.run('themed-component-usages', tsRule as any, {
|
||||
@@ -90,7 +90,7 @@ const config = {
|
||||
a: ThemedTestThemeableComponent,
|
||||
b: TestComponent,
|
||||
}
|
||||
`
|
||||
`,
|
||||
},
|
||||
{
|
||||
filename: fixture('src/app/test/test.component.spec.ts'),
|
||||
@@ -260,6 +260,6 @@ class Test {
|
||||
<ds-test-themeable [test]="something"></ds-test-themeable>
|
||||
`,
|
||||
},
|
||||
]
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@@ -6,8 +6,9 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
|
||||
import { RuleTester } from 'eslint';
|
||||
import { RuleTester as TypeScriptRuleTester } from '@typescript-eslint/rule-tester';
|
||||
import { RuleTester } from 'eslint';
|
||||
|
||||
import { themeableComponents } from '../src/util/theme-support';
|
||||
|
||||
const FIXTURE = 'lint/test/fixture/';
|
||||
@@ -29,7 +30,7 @@ export const tsRuleTester = new TypeScriptRuleTester({
|
||||
},
|
||||
parserOptions: {
|
||||
project: fixture('tsconfig.json'),
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
class HtmlRuleTester extends RuleTester {
|
||||
|
Reference in New Issue
Block a user