mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
117616: Created documentation for the custom lint options
This commit is contained in:
@@ -9,6 +9,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/html/no-disabled-attribute-on-button.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -11,6 +11,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/html/themed-component-usages.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -7,6 +7,21 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/alias-imports.ts)
|
||||
|
||||
|
||||
### Options
|
||||
|
||||
#### `aliases`
|
||||
|
||||
A list of all the imports that you want to alias for clarity. Every alias should be declared in the following format:
|
||||
```json
|
||||
{
|
||||
"package": "rxjs",
|
||||
"imported": "of",
|
||||
"local": "observableOf"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -11,6 +11,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/themed-component-classes.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -17,6 +17,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/themed-component-selectors.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -15,6 +15,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/themed-component-usages.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -7,6 +7,14 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/themed-decorators.ts)
|
||||
|
||||
|
||||
### Options
|
||||
|
||||
#### `decorators`
|
||||
|
||||
A mapping for all the existing themeable decorators, with the decorator name as the key and the index of the `theme` argument as the value.
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -7,6 +7,8 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/themed-wrapper-no-input-defaults.ts)
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -7,6 +7,14 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/ts/unique-decorators.ts)
|
||||
|
||||
|
||||
### Options
|
||||
|
||||
#### `decorators`
|
||||
|
||||
The list of all the decorators for which you want to enforce this behavior.
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
@@ -33,6 +33,7 @@ export const info = {
|
||||
[Message.USE_DSBTN_DISABLED]: 'Buttons should use the `dsBtnDisabled` directive instead of the `disabled` attribute.',
|
||||
},
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
} as DSpaceESLintRuleInfo;
|
||||
|
||||
|
@@ -45,6 +45,7 @@ The only exception to this rule are unit tests, where we may want to use the bas
|
||||
[Message.WRONG_SELECTOR]: 'Themeable components should be used via their ThemedComponent wrapper\'s selector',
|
||||
},
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
} as DSpaceESLintRuleInfo;
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import { Scope } from '@typescript-eslint/utils/ts-eslint';
|
||||
import {
|
||||
DSpaceESLintRuleInfo,
|
||||
NamedTests,
|
||||
OptionDoc,
|
||||
} from '../../util/structure';
|
||||
|
||||
export enum Message {
|
||||
@@ -17,13 +18,21 @@ export enum Message {
|
||||
MULTIPLE_ALIASES = 'multipleAliases',
|
||||
}
|
||||
|
||||
interface AliasImportOptions {
|
||||
aliases: AliasImportOption[];
|
||||
}
|
||||
|
||||
interface AliasImportOption {
|
||||
package: string;
|
||||
imported: string;
|
||||
local: string;
|
||||
}
|
||||
|
||||
export const info: DSpaceESLintRuleInfo<[[AliasImportOption]]> = {
|
||||
interface AliasImportDocOptions {
|
||||
aliases: OptionDoc;
|
||||
}
|
||||
|
||||
export const info: DSpaceESLintRuleInfo<[AliasImportOptions], [AliasImportDocOptions]> = {
|
||||
name: 'alias-imports',
|
||||
meta: {
|
||||
docs: {
|
||||
@@ -36,35 +45,50 @@ export const info: DSpaceESLintRuleInfo<[[AliasImportOption]]> = {
|
||||
},
|
||||
fixable: 'code',
|
||||
type: 'problem',
|
||||
schema: [
|
||||
{
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
package: { type: 'string' },
|
||||
imported: { type: 'string' },
|
||||
local: { type: 'string' },
|
||||
},
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
package: { type: 'string' },
|
||||
imported: { type: 'string' },
|
||||
local: { type: 'string' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
defaultOptions: [
|
||||
[
|
||||
{
|
||||
package: 'rxjs',
|
||||
imported: 'of',
|
||||
local: 'observableOf',
|
||||
optionDocs: [
|
||||
{
|
||||
aliases: {
|
||||
title: '`aliases`',
|
||||
description: `A list of all the imports that you want to alias for clarity. Every alias should be declared in the following format:
|
||||
\`\`\`json
|
||||
{
|
||||
"package": "rxjs",
|
||||
"imported": "of",
|
||||
"local": "observableOf"
|
||||
}
|
||||
\`\`\``,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
defaultOptions: [
|
||||
{
|
||||
aliases: [
|
||||
{
|
||||
package: 'rxjs',
|
||||
imported: 'of',
|
||||
local: 'observableOf',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const rule = ESLintUtils.RuleCreator.withoutDocs({
|
||||
...info,
|
||||
create(context: TSESLint.RuleContext<Message, unknown[]>, options: any) {
|
||||
return options[0].reduce((selectors: any, option: AliasImportOption) => {
|
||||
return (options[0] as AliasImportOptions).aliases.reduce((selectors: any, option: AliasImportOption) => {
|
||||
selectors[`ImportDeclaration[source.value = "${option.package}"] > ImportSpecifier[imported.name = "${option.imported}"][local.name != "${option.local}"]`] = (node: TSESTree.ImportSpecifier) => handleUnaliasedImport(context, option, node);
|
||||
return selectors;
|
||||
}, {});
|
||||
|
@@ -52,6 +52,7 @@ export const info = {
|
||||
[Message.WRAPPER_IMPORTS_BASE]: 'Themed component wrapper classes must only import the base class',
|
||||
},
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
} as DSpaceESLintRuleInfo;
|
||||
|
||||
|
@@ -53,6 +53,7 @@ Unit tests are exempt from this rule, because they may redefine components using
|
||||
[Message.THEMED]: 'Theme override of themeable component should have a selector starting with \'ds-themed-\'',
|
||||
},
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
} as DSpaceESLintRuleInfo;
|
||||
|
||||
|
@@ -63,6 +63,7 @@ There are a few exceptions where the base class can still be used:
|
||||
[Message.BASE_IN_MODULE]: 'Base themeable components shouldn\'t be declared in modules',
|
||||
},
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
} as DSpaceESLintRuleInfo;
|
||||
|
||||
|
@@ -10,6 +10,7 @@ import { isTestFile } from '../../util/filter';
|
||||
import {
|
||||
DSpaceESLintRuleInfo,
|
||||
NamedTests,
|
||||
OptionDoc,
|
||||
} from '../../util/structure';
|
||||
import { getFileTheme } from '../../util/theme-support';
|
||||
|
||||
@@ -23,7 +24,11 @@ interface ThemedDecoratorsOption {
|
||||
decorators: { [name: string]: number };
|
||||
}
|
||||
|
||||
export const info: DSpaceESLintRuleInfo<[ThemedDecoratorsOption]> = {
|
||||
interface ThemedDecoratorsDocsOption {
|
||||
decorators: OptionDoc;
|
||||
}
|
||||
|
||||
export const info: DSpaceESLintRuleInfo<[ThemedDecoratorsOption], [ThemedDecoratorsDocsOption]> = {
|
||||
name: 'themed-decorators',
|
||||
meta: {
|
||||
docs: {
|
||||
@@ -47,6 +52,14 @@ export const info: DSpaceESLintRuleInfo<[ThemedDecoratorsOption]> = {
|
||||
},
|
||||
],
|
||||
},
|
||||
optionDocs: [
|
||||
{
|
||||
decorators: {
|
||||
title: '`decorators`',
|
||||
description: 'A mapping for all the existing themeable decorators, with the decorator name as the key and the index of the `theme` argument as the value.',
|
||||
},
|
||||
},
|
||||
],
|
||||
defaultOptions: [
|
||||
{
|
||||
decorators: {
|
||||
|
@@ -26,6 +26,7 @@ export const info: DSpaceESLintRuleInfo = {
|
||||
type: 'problem',
|
||||
schema: [],
|
||||
},
|
||||
optionDocs: [],
|
||||
defaultOptions: [],
|
||||
};
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import { isTestFile } from '../../util/filter';
|
||||
import {
|
||||
DSpaceESLintRuleInfo,
|
||||
NamedTests,
|
||||
OptionDoc,
|
||||
} from '../../util/structure';
|
||||
|
||||
export enum Message {
|
||||
@@ -17,7 +18,15 @@ export enum Message {
|
||||
|
||||
const decoratorCalls: Map<string, Set<string>> = new Map();
|
||||
|
||||
export const info: DSpaceESLintRuleInfo = {
|
||||
export interface UniqueDecoratorsOptions {
|
||||
decorators: string[];
|
||||
}
|
||||
|
||||
export interface UniqueDecoratorsDocOptions {
|
||||
decorators: OptionDoc;
|
||||
}
|
||||
|
||||
export const info: DSpaceESLintRuleInfo<[UniqueDecoratorsOptions], [UniqueDecoratorsDocOptions]> = {
|
||||
name: 'unique-decorators',
|
||||
meta: {
|
||||
docs: {
|
||||
@@ -41,6 +50,14 @@ export const info: DSpaceESLintRuleInfo = {
|
||||
},
|
||||
],
|
||||
},
|
||||
optionDocs: [
|
||||
{
|
||||
decorators: {
|
||||
title: '`decorators`',
|
||||
description: 'The list of all the decorators for which you want to enforce this behavior.',
|
||||
},
|
||||
},
|
||||
],
|
||||
defaultOptions: [
|
||||
{
|
||||
decorators: [
|
||||
|
@@ -17,12 +17,18 @@ export type Meta = RuleMetaData<string, unknown[]>;
|
||||
export type Valid = ValidTestCase<unknown[]>;
|
||||
export type Invalid = InvalidTestCase<string, unknown[]>;
|
||||
|
||||
export interface DSpaceESLintRuleInfo<T = unknown[]> {
|
||||
export interface DSpaceESLintRuleInfo<T = unknown[], D = unknown[]> {
|
||||
name: string;
|
||||
meta: Meta,
|
||||
optionDocs: D,
|
||||
defaultOptions: T,
|
||||
}
|
||||
|
||||
export interface OptionDoc {
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface NamedTests {
|
||||
plugin: string;
|
||||
valid: Valid[];
|
||||
|
@@ -7,6 +7,11 @@ _______
|
||||
|
||||
[Source code](../../../../lint/src/rules/<%- plugin.name.replace('dspace-angular-', '') %>/<%- rule.name %>.ts)
|
||||
|
||||
<% if (rule.optionDocs?.length > 0) { %>
|
||||
### Options
|
||||
<%- rule.optionDocs.map(optionDoc => Object.keys(optionDoc).map(option => '\n#### ' + optionDoc[option].title + '\n\n' + optionDoc[option].description)) %>
|
||||
<% } %>
|
||||
|
||||
### Examples
|
||||
|
||||
<% if (tests.valid) {%>
|
||||
|
Reference in New Issue
Block a user