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,
valid: [
{
name: 'use no-prefix selectors in HTML templates',
code: `
<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: `
@Component({
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'),
code: `
@Component({
@@ -119,6 +122,7 @@ class Test {
`,
},
{
name: 'base selectors are also allowed in TypeScript test templates',
filename: fixture('src/test.spec.ts'),
code: `
@Component({
@@ -131,6 +135,7 @@ class Test {
],
invalid: [
{
name: 'themed override selectors are not allowed in HTML templates',
code: `
<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: `
<ds-base-test-themeable/>
<ds-base-test-themeable></ds-base-test-themeable>

View File

@@ -45,7 +45,7 @@ export const info = {
messages: {
[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.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: [],

View File

@@ -48,8 +48,8 @@ Unit tests are exempt from this rule, because they may redefine components using
schema: [],
fixable: 'code',
messages: {
[Message.BASE]: 'Unthemed version of themeable components 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.BASE]: 'Unthemed version of themeable component should have a selector starting with \'ds-base-\'',
[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-\'',
},
},

View File

@@ -242,7 +242,7 @@ export class Something {
filename: fixture('src/app/test/test.component.spec.ts'),
code: `
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'),
code: `
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
_______
<% 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) {%>
#### Valid code
<% tests.valid.forEach(test => { %>
##### <%= test.name !== undefined ? test.name : 'UNNAMED' %>
<% if (test.filename) { %>
Filename: `<%- test.filename %>`
<% } %>
```
```<%- plugin.language.toLowerCase() %>
<%- test.code.trim() %>
```
<% }) %>
<% } %>
<% if (tests.invalid) {%>
#### Invalid code
#### Invalid code <%= rule.meta.fixable ? ' & automatic fixes' : '' %>
<% tests.invalid.forEach(test => { %>
##### <%= test.name !== undefined ? test.name : 'UNNAMED' %>
<% if (test.filename) { %>
Filename: `<%- test.filename %>`
<% } %>
```
```<%- plugin.language.toLowerCase() %>
<%- 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() %>
```
<% } %>
<% }) %>
<% } %>