Skip to content

Commit

Permalink
Link ESLint rules to local documentation
Browse files Browse the repository at this point in the history
We can also link to external documentation on GitHub, but it may contain the wrong version, and local files should integrate nicely with most IDEs (to be tested)
  • Loading branch information
ybnd committed Sep 21, 2024
1 parent 779ff47 commit ae1d1de
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/lint/html/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/index.ejs -->
[DSpace ESLint plugins](../../../lint/README.md) > HTML rules
_______

Expand Down
1 change: 1 addition & 0 deletions docs/lint/html/rules/themed-component-usages.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/rule.ejs -->
[DSpace ESLint plugins](../../../../lint/README.md) > [HTML rules](../index.md) > `dspace-angular-html/themed-component-usages`
_______

Expand Down
1 change: 1 addition & 0 deletions docs/lint/ts/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/index.ejs -->
[DSpace ESLint plugins](../../../lint/README.md) > TypeScript rules
_______

Expand Down
1 change: 1 addition & 0 deletions docs/lint/ts/rules/themed-component-classes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/rule.ejs -->
[DSpace ESLint plugins](../../../../lint/README.md) > [TypeScript rules](../index.md) > `dspace-angular-ts/themed-component-classes`
_______

Expand Down
1 change: 1 addition & 0 deletions docs/lint/ts/rules/themed-component-selectors.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/rule.ejs -->
[DSpace ESLint plugins](../../../../lint/README.md) > [TypeScript rules](../index.md) > `dspace-angular-ts/themed-component-selectors`
_______

Expand Down
1 change: 1 addition & 0 deletions docs/lint/ts/rules/themed-component-usages.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/rule.ejs -->
[DSpace ESLint plugins](../../../../lint/README.md) > [TypeScript rules](../index.md) > `dspace-angular-ts/themed-component-usages`
_______

Expand Down
4 changes: 2 additions & 2 deletions lint/src/rules/html/themed-component-usages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/
import { TmplAstElement } from '@angular-eslint/bundled-angular-compiler';
import { TemplateParserServices } from '@angular-eslint/utils';
import { ESLintUtils } from '@typescript-eslint/utils';
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';

import { fixture } from '../../../test/fixture';
import {
createHtmlRule,
DSpaceESLintRuleInfo,
NamedTests,
} from '../../util/structure';
Expand Down Expand Up @@ -48,7 +48,7 @@ The only exception to this rule are unit tests, where we may want to use the bas
defaultOptions: [],
} as DSpaceESLintRuleInfo;

export const rule = ESLintUtils.RuleCreator.withoutDocs({
export const rule = createHtmlRule({
...info,
create(context: RuleContext<Message, unknown[]>) {
if (getFilename(context).includes('.spec.ts')) {
Expand Down
12 changes: 6 additions & 6 deletions lint/src/rules/ts/themed-component-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
*
* http://www.dspace.org/license/
*/
import {
ESLintUtils,
TSESTree,
} from '@typescript-eslint/utils';
import { TSESTree } from '@typescript-eslint/utils';
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';

import { fixture } from '../../../test/fixture';
Expand All @@ -18,7 +15,10 @@ import {
getComponentStandaloneNode,
} from '../../util/angular';
import { appendObjectProperties } from '../../util/fix';
import { DSpaceESLintRuleInfo } from '../../util/structure';
import {
createTsRule,
DSpaceESLintRuleInfo,
} from '../../util/structure';
import {
getBaseComponentClassName,
inThemedComponentOverrideFile,
Expand Down Expand Up @@ -55,7 +55,7 @@ export const info = {
defaultOptions: [],
} as DSpaceESLintRuleInfo;

export const rule = ESLintUtils.RuleCreator.withoutDocs({
export const rule = createTsRule({
...info,
create(context: RuleContext<Message, unknown[]>) {
const filename = getFilename(context);
Expand Down
12 changes: 6 additions & 6 deletions lint/src/rules/ts/themed-component-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*
* http://www.dspace.org/license/
*/
import {
ESLintUtils,
TSESTree,
} from '@typescript-eslint/utils';
import { TSESTree } from '@typescript-eslint/utils';
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';

import { fixture } from '../../../test/fixture';
import { getComponentSelectorNode } from '../../util/angular';
import { stringLiteral } from '../../util/misc';
import { DSpaceESLintRuleInfo } from '../../util/structure';
import {
createTsRule,
DSpaceESLintRuleInfo,
} from '../../util/structure';
import {
inThemedComponentOverrideFile,
isThemeableComponent,
Expand Down Expand Up @@ -56,7 +56,7 @@ Unit tests are exempt from this rule, because they may redefine components using
defaultOptions: [],
} as DSpaceESLintRuleInfo;

export const rule = ESLintUtils.RuleCreator.withoutDocs({
export const rule = createTsRule({
...info,
create(context: RuleContext<Message, unknown[]>) {
const filename = getFilename(context);
Expand Down
12 changes: 6 additions & 6 deletions lint/src/rules/ts/themed-component-usages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*
* http://www.dspace.org/license/
*/
import {
ESLintUtils,
TSESTree,
} from '@typescript-eslint/utils';
import { TSESTree } from '@typescript-eslint/utils';
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';

import { fixture } from '../../../test/fixture';
import {
removeWithCommas,
replaceOrRemoveArrayIdentifier,
} from '../../util/fix';
import { DSpaceESLintRuleInfo } from '../../util/structure';
import {
createTsRule,
DSpaceESLintRuleInfo,
} from '../../util/structure';
import {
allThemeableComponents,
DISALLOWED_THEME_SELECTORS,
Expand Down Expand Up @@ -66,7 +66,7 @@ There are a few exceptions where the base class can still be used:
defaultOptions: [],
} as DSpaceESLintRuleInfo;

export const rule = ESLintUtils.RuleCreator.withoutDocs({
export const rule = createTsRule({
...info,
create(context: RuleContext<Message, unknown[]>) {
const filename = getFilename(context);
Expand Down
17 changes: 14 additions & 3 deletions lint/src/util/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
*
* http://www.dspace.org/license/
*/
import { ESLintUtils } from '@typescript-eslint/utils';
import { NamedCreateRuleMeta } from '@typescript-eslint/utils/eslint-utils';
import {
InvalidTestCase,
RuleMetaData,
RuleModule,
ValidTestCase,
} from '@typescript-eslint/utils/ts-eslint';
import { EnumType } from 'typescript';

export type Meta = RuleMetaData<string, unknown[]>;
export type Meta = NamedCreateRuleMeta<string, unknown[]>;
export type Valid = ValidTestCase<unknown[]>;
export type Invalid = InvalidTestCase<string, unknown[]>;

Expand Down Expand Up @@ -44,6 +45,16 @@ export interface PluginExports {
index: RuleExports[],
}

const DOCUMENTATION = `file://${process.cwd()}/docs/lint`;

export const createTsRule = ESLintUtils.RuleCreator(
name => `${DOCUMENTATION}/ts/rules/${name}.md`,
);

export const createHtmlRule = ESLintUtils.RuleCreator(
name => `${DOCUMENTATION}/html/rules/${name}.md`,
);

export function bundle(
name: string,
language: string,
Expand All @@ -58,4 +69,4 @@ export function bundle(
rules: {},
index,
});
}
}
1 change: 1 addition & 0 deletions lint/src/util/templates/index.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/index.ejs -->
[DSpace ESLint plugins](../../../lint/README.md) > <%= plugin.language %> rules
_______
<% rules.forEach(rule => { %>
Expand Down
1 change: 1 addition & 0 deletions lint/src/util/templates/rule.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- GENERATED ~ lint/src/util/templates/rule.ejs -->
[DSpace ESLint plugins](../../../../lint/README.md) > [<%= plugin.language %> rules](../index.md) > `<%= plugin.name %>/<%= rule.name %>`
_______

Expand Down
5 changes: 3 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ import {
NativeWindowService,
} from './core/services/window.service';
import { distinctNext } from './core/shared/distinct-next';
import { ThemedRootComponent } from './root/themed-root.component';
import { RootComponent } from './root/root.component';
import { HostWindowResizeAction } from './shared/host-window.actions';
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
import { CSSVariableService } from './shared/sass-helper/css-variable.service';
import { HostWindowState } from './shared/search/host-window.reducer';
import { ThemeService } from './shared/theme-support/theme.service';


@Component({
selector: 'ds-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
ThemedRootComponent,
RootComponent,
AsyncPipe,
],
})
Expand Down

0 comments on commit ae1d1de

Please sign in to comment.