Improve documentation

This commit is contained in:
Yury Bondarenko
2024-03-29 10:46:20 +01:00
parent 2c68589416
commit 515e5f00cf
6 changed files with 30 additions and 12 deletions

View File

@@ -93,6 +93,7 @@ export const tests = {
plugin: info.name, plugin: info.name,
valid: [ valid: [
{ {
name: 'use no-prefix selectors in HTML templates',
code: ` code: `
<ds-test-themeable/> <ds-test-themeable/>
<ds-test-themeable></ds-test-themeable> <ds-test-themeable></ds-test-themeable>
@@ -100,6 +101,7 @@ export const tests = {
`, `,
}, },
{ {
name: 'use no-prefix selectors in TypeScript templates',
code: ` code: `
@Component({ @Component({
template: '<ds-test-themeable></ds-test-themeable>' template: '<ds-test-themeable></ds-test-themeable>'
@@ -109,6 +111,7 @@ class Test {
`, `,
}, },
{ {
name: 'use no-prefix selectors in TypeScript test templates',
filename: fixture('src/test.spec.ts'), filename: fixture('src/test.spec.ts'),
code: ` code: `
@Component({ @Component({
@@ -119,6 +122,7 @@ class Test {
`, `,
}, },
{ {
name: 'base selectors are also allowed in TypeScript test templates',
filename: fixture('src/test.spec.ts'), filename: fixture('src/test.spec.ts'),
code: ` code: `
@Component({ @Component({
@@ -131,6 +135,7 @@ class Test {
], ],
invalid: [ invalid: [
{ {
name: 'themed override selectors are not allowed in HTML templates',
code: ` code: `
<ds-themed-test-themeable/> <ds-themed-test-themeable/>
<ds-themed-test-themeable></ds-themed-test-themeable> <ds-themed-test-themeable></ds-themed-test-themeable>
@@ -154,6 +159,7 @@ class Test {
`, `,
}, },
{ {
name: 'base selectors are not allowed in HTML templates',
code: ` code: `
<ds-base-test-themeable/> <ds-base-test-themeable/>
<ds-base-test-themeable></ds-base-test-themeable> <ds-base-test-themeable></ds-base-test-themeable>

View File

@@ -45,7 +45,7 @@ export const info = {
messages: { messages: {
[Message.NOT_STANDALONE]: 'Themeable components must be standalone', [Message.NOT_STANDALONE]: 'Themeable components must be standalone',
[Message.NOT_STANDALONE_IMPORTS_BASE]: 'Themeable component wrapper classes must be standalone and import the base class', [Message.NOT_STANDALONE_IMPORTS_BASE]: 'Themeable component wrapper classes must be standalone and import the base class',
[Message.WRAPPER_IMPORTS_BASE]: 'Themed component wrapper classes must import the base class', [Message.WRAPPER_IMPORTS_BASE]: 'Themed component wrapper classes must only import the base class',
}, },
}, },
defaultOptions: [], defaultOptions: [],

View File

@@ -48,8 +48,8 @@ Unit tests are exempt from this rule, because they may redefine components using
schema: [], schema: [],
fixable: 'code', fixable: 'code',
messages: { messages: {
[Message.BASE]: 'Unthemed version of themeable components should have a selector starting with \'ds-base-\'', [Message.BASE]: 'Unthemed version of themeable component should have a selector starting with \'ds-base-\'',
[Message.WRAPPER]: 'Themed component wrapper of themeable components shouldn\'t have a selector starting with \'ds-themed-\'', [Message.WRAPPER]: 'Themed component wrapper of themeable component shouldn\'t have a selector starting with \'ds-themed-\'',
[Message.THEMED]: 'Theme override of themeable component should have a selector starting with \'ds-themed-\'', [Message.THEMED]: 'Theme override of themeable component should have a selector starting with \'ds-themed-\'',
}, },
}, },

View File

@@ -242,7 +242,7 @@ export class Something {
filename: fixture('src/app/test/test.component.spec.ts'), filename: fixture('src/app/test/test.component.spec.ts'),
code: ` code: `
By.css('ds-themeable'); By.css('ds-themeable');
By.Css('#test > ds-themeable > #nest'); By.css('#test > ds-themeable > #nest');
`, `,
}, },
{ {
@@ -250,7 +250,7 @@ By.Css('#test > ds-themeable > #nest');
filename: fixture('src/app/test/test.component.cy.ts'), filename: fixture('src/app/test/test.component.cy.ts'),
code: ` code: `
By.css('ds-themeable'); By.css('ds-themeable');
By.Css('#test > ds-themeable > #nest'); By.css('#test > ds-themeable > #nest');
`, `,
}, },
], ],

View File

@@ -1,5 +1,5 @@
[DSpace ESLint plugins](../../../lint/README.md) > <%= plugin.language %> rules [DSpace ESLint plugins](../../../lint/README.md) > <%= plugin.language %> rules
_______
<% rules.forEach(rule => { %> <% rules.forEach(rule => { %>
- [`<%= plugin.name %>/<%= rule.name %>`](./rules/<%= rule.name %>.md)<% if (rule.meta?.docs?.description) {%>: <%= rule.meta.docs.description.split('\n')[0] %><% }%> - [`<%= plugin.name %>/<%= rule.name %>`](./rules/<%= rule.name %>.md)<% if (rule.meta?.docs?.description) {%>: <%= rule.meta.docs.description.split('\n')[0].trim() -%><% }-%>
<% }) %> <% }) %>

View File

@@ -12,25 +12,37 @@ _______
<% if (tests.valid) {%> <% if (tests.valid) {%>
#### Valid code #### Valid code
<% tests.valid.forEach(test => { %> <% tests.valid.forEach(test => { %>
##### <%= test.name !== undefined ? test.name : 'UNNAMED' %>
<% if (test.filename) { %> <% if (test.filename) { %>
Filename: `<%- test.filename %>` Filename: `<%- test.filename %>`
<% } %> <% } %>
``` ```<%- plugin.language.toLowerCase() %>
<%- test.code.trim() %> <%- test.code.trim() %>
``` ```
<% }) %> <% }) %>
<% } %> <% } %>
<% if (tests.invalid) {%> <% if (tests.invalid) {%>
#### Invalid code #### Invalid code <%= rule.meta.fixable ? ' & automatic fixes' : '' %>
<% tests.invalid.forEach(test => { %> <% tests.invalid.forEach(test => { %>
##### <%= test.name !== undefined ? test.name : 'UNNAMED' %>
<% if (test.filename) { %> <% if (test.filename) { %>
Filename: `<%- test.filename %>` Filename: `<%- test.filename %>`
<% } %> <% } %>
``` ```<%- plugin.language.toLowerCase() %>
<%- test.code.trim() %> <%- test.code.trim() %>
``` ```
Will produce the following error(s):
```
<% for (const error of test.errors) { -%>
<%- rule.meta.messages[error.messageId] %>
<% } -%>
```
<% if (test.output) { %>
Result of `yarn lint --fix`:
```<%- plugin.language.toLowerCase() %>
<%- test.output.trim() %>
```
<% } %>
<% }) %> <% }) %>
<% } %> <% } %>