Skip to content

Commit

Permalink
docs: update developer tools (#3382)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored Apr 28, 2022
1 parent bf2672e commit 9fcd553
Show file tree
Hide file tree
Showing 53 changed files with 576 additions and 328 deletions.
24 changes: 24 additions & 0 deletions build/generate-eslint-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createBuilder } from './util';

const update = createBuilder([
[
'Update config',
() => require('../modules/eslint-plugin/scripts/generate-config'),
],
[
'Update overview',
() => require('../modules/eslint-plugin/scripts/generate-overview'),
],
[
'Update docs',
() => require('../modules/eslint-plugin/scripts/generate-docs'),
],
]);

update({
scope: '@ngrx',
packages: [{ name: 'eslint-plugin' }],
}).catch((err) => {
console.error(err);
process.exit(1);
});
11 changes: 5 additions & 6 deletions modules/eslint-plugin/scripts/generate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { rules } from '../src/rules';

const prettierConfig = resolveConfig.sync(__dirname);

const RULE_NAME_PREFIX = 'ngrx/';
const CONFIG_DIRECTORY = './src/configs/';
const RULE_MODULE = '@ngrx';
const CONFIG_DIRECTORY = './modules/eslint-plugin/src/configs/';

writeConfig(
'recommended',
Expand Down Expand Up @@ -113,7 +113,7 @@ function writeConfig(
);
const configRules = rulesForConfig.reduce<Record<string, string>>(
(rules, [ruleName, rule]) => {
rules[`${RULE_NAME_PREFIX}${ruleName}`] = setting(rule);
rules[`${RULE_MODULE}/${ruleName}`] = setting(rule);
return rules;
},
{}
Expand All @@ -130,14 +130,13 @@ function writeConfig(
const code = `
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/
export = {
parser: "@typescript-eslint/parser",
${parserOptions ? `parserOptions: ${JSON.stringify(parserOptions)},` : ''}
plugins: ["ngrx"],
plugins: ["${RULE_MODULE}"],
rules: ${JSON.stringify(configRules)},
}
`;
Expand Down
27 changes: 15 additions & 12 deletions modules/eslint-plugin/scripts/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ import { format, resolveConfig } from 'prettier';
import { rules } from '../src/rules';

const prettierConfig = resolveConfig.sync(__dirname);
const placeholder = '<!-- MANUAL-DOC:START -->';
const PLACEHOLDER = '<!-- MANUAL-DOC:START -->';
const RULES_PATH = './projects/ngrx.io/content/guide/eslint-plugin/rules';

for (const [ruleName, { meta }] of Object.entries(rules)) {
const docPath = path.join('docs', 'rules', `${ruleName}.md`);
const docPath = path.join(RULES_PATH, `${ruleName}.md`);
const doc = readFileSync(docPath, 'utf-8');
const docContent = doc.substr(doc.indexOf(placeholder) + placeholder.length);
const frontMatter = [
`Fixable: ${meta.fixable ? 'yes' : 'no'}`,
meta.version ? `Required NgRx Version Range: ${meta.version}` : '',
];
const docContent = doc.substr(doc.indexOf(PLACEHOLDER) + PLACEHOLDER.length);
const newDoc = format(
`---
${frontMatter.filter(Boolean).join('\n')}
---
# ${ruleName}
`# ${ruleName}
> ${meta.docs?.description}
${meta.version ? '> Required NgRx Version Range: ${meta.version}' : ''}
${meta.docs?.description}
- **Type**: ${meta.type}
- **Recommended**: ${meta.docs?.recommended ? 'Yes' : 'No'}
- **Fixable**: ${meta.fixable ? 'Yes' : 'No'}
- **Suggestion**: ${meta.hasSuggestions ? 'Yes' : 'No'}
- **Requires type checking**: ${meta.docs?.requiresTypeChecking ? 'Yes' : 'No'}
- **Configurable**: ${meta.schema.length ? 'Yes' : 'No'}
<!-- Everything above this generated, do not edit -->
<!-- MANUAL-DOC:START -->
Expand Down
101 changes: 101 additions & 0 deletions modules/eslint-plugin/scripts/generate-overview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { readFileSync, writeFileSync } from 'fs';
import { EOL } from 'os';
import { format, resolveConfig } from 'prettier';
import { rules } from '../src/rules';
import { configs } from '../src/configs';

const prettierConfig = resolveConfig.sync(__dirname);
const OVERVIEW = './projects/ngrx.io/content/guide/eslint-plugin/overview.md';
const GH_CONFIGS =
'https://github.com/ngrx/platform/blob/master/modules/eslint-plugin/src/configs';

generateRules();
generateConfigurations();

function generateRules() {
const moduleRules = Object.entries(rules).reduce<Record<string, string[][]>>(
(all, [ruleName, { meta }]) => {
all[meta.ngrxModule] = (all[meta.ngrxModule] ?? []).concat([
[
`[@ngrx/${ruleName}]${
meta.docs?.url
? '(' +
meta.docs.url
.replace('https://ngrx.io', '')
.replace('.md', '') +
')'
: ''
}`,
meta.docs?.description ?? 'TODO',
meta.type,
`${meta.docs?.recommended}`,
meta.fixable ? 'Yes' : 'No',
meta.hasSuggestions ? 'Yes' : 'No',
meta.schema.length ? 'Yes' : 'No',
meta.docs?.requiresTypeChecking ? 'Yes' : 'No',
],
]);
return all;
},
{}
);

const tableHeader = `| Name | Description | Recommended | Category | Fixable | Has suggestions | Configurable | Requires type information
| --- | --- | --- | --- | --- | --- | --- | --- |`;

const configTable = Object.entries(moduleRules).map(
([ngrxModule, pluginRules]) => {
const tableBody = pluginRules
.map((rule) => `|${rule.join('|')}|`)
.join(EOL);
const table = [tableHeader, tableBody].join(EOL);

return [`### ${ngrxModule}`, table].join(EOL);
}
);

const overview = readFileSync(OVERVIEW, 'utf-8');
const start = overview.indexOf('<!-- RULES-CONFIG:START -->');
const end = overview.indexOf('<!-- RULES-CONFIG:END -->');

const newOverview = format(
`${overview.substring(0, start + '<!-- RULES-CONFIG:START -->'.length)}
${configTable.join(EOL)}
${overview.substring(end)}`,
{
parser: 'markdown',
...prettierConfig,
}
);

writeFileSync(OVERVIEW, newOverview);
}

function generateConfigurations() {
const tableHeader = `| Name |
| --- |`;

const config = Object.keys(configs);

const overview = readFileSync(OVERVIEW, 'utf-8');
const start = overview.indexOf('<!-- CONFIGURATIONS-CONFIG:START -->');
const end = overview.indexOf('<!-- CONFIGURATIONS-CONFIG:END -->');

const configTable = config.map(
(configName) => `| [${configName}](${GH_CONFIGS}/${configName}.ts) |`
);
const newOverview = format(
`${overview.substring(
0,
start + '<!-- CONFIGURATIONS-CONFIG:START -->'.length
)}
${[tableHeader, ...configTable].join(EOL)}
${overview.substring(end)}`,
{
parser: 'markdown',
...prettierConfig,
}
);

writeFileSync(OVERVIEW, newOverview);
}
50 changes: 0 additions & 50 deletions modules/eslint-plugin/scripts/generate-readme.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/all.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/component-store-strict.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/component-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/effects-strict.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/effects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/recommended.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/store-strict.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
3 changes: 1 addition & 2 deletions modules/eslint-plugin/src/configs/strict.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* DO NOT EDIT
*
* This file is automatically generated (as a pre-commit step)
* This file is generated
*/

export = {
Expand Down
2 changes: 1 addition & 1 deletion modules/eslint-plugin/src/utils/helper-functions/docs.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const docsUrl = (ruleName: string) =>
`https://github.com/timdeschryver/eslint-plugin-ngrx/tree/main/docs/rules/${ruleName}.md`;
`https://ngrx.io/guide/eslint-plugin/rules/${ruleName}.md`;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"lint": "nx workspace-lint && ng lint",
"dep-graph": "nx dep-graph",
"help": "nx help",
"workspace-generator": "nx workspace-generator"
"workspace-generator": "nx workspace-generator",
"eslint-plugin:update": "ts-node ./build/generate-eslint-plugin.ts"
},
"engines": {
"node": "^12.20.0 || >=14.0.0",
Expand Down
Loading

0 comments on commit 9fcd553

Please sign in to comment.