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