@activatus/code-standards 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+ // Standard 21: AGENTS.md, its code standards section and version,
2
+ // and the agent skills.
3
+ import { readdirSync } from "node:fs";
4
+ import path from "node:path";
5
+
6
+ import { readTextFile } from "./projectFiles.mjs";
7
+
8
+ const SECTION_START = "<!-- code-standards:start -->";
9
+ const SECTION_END = "<!-- code-standards:end -->";
10
+ const VERSION_LINE_START = "**Code standards version:**";
11
+ const VERSION_PATTERN = /\*\*Code standards version:\*\*\s*(\d+)/;
12
+ const SKILL_FOLDERS = [".agents/skills", ".claude/commands"];
13
+ const PAGE = "docs/Standards/agent-specs.md";
14
+
15
+ // The text between the markers, without the version line: the project
16
+ // fills that line in, and everything else is copied unchanged.
17
+ const readStandardsSection = (agentsText) => {
18
+ const startIndex = agentsText.indexOf(SECTION_START);
19
+ const endIndex = agentsText.indexOf(SECTION_END);
20
+ const hasMarkers = startIndex !== -1 && endIndex !== -1;
21
+ return hasMarkers
22
+ ? agentsText
23
+ .slice(startIndex + SECTION_START.length, endIndex)
24
+ .replaceAll("\r\n", "\n")
25
+ .split("\n")
26
+ .filter((line) => !line.startsWith(VERSION_LINE_START))
27
+ .join("\n")
28
+ .trim()
29
+ : undefined;
30
+ };
31
+
32
+ const checkVersion = ({ agentsText, packageMajorVersion }) => {
33
+ const match = VERSION_PATTERN.exec(agentsText);
34
+ if (!match) {
35
+ return [
36
+ {
37
+ standard: "21",
38
+ message:
39
+ "AGENTS.md has no code standards version. Set **Code standards version:** to the major version the code follows",
40
+ page: "docs/Guides/setup.md",
41
+ },
42
+ ];
43
+ }
44
+ const projectVersion = Number(match[1]);
45
+ if (projectVersion < packageMajorVersion) {
46
+ return [
47
+ {
48
+ standard: "21",
49
+ message: `AGENTS.md says version ${projectVersion}, and the installed package is version ${packageMajorVersion}. Follow "Updating to a newer version"`,
50
+ page: "docs/Guides/setup.md#updating-to-a-newer-version",
51
+ },
52
+ ];
53
+ }
54
+ return [];
55
+ };
56
+
57
+ const checkStandardsSection = ({
58
+ agentsText,
59
+ templatesDirectory,
60
+ }) => {
61
+ const projectSection = readStandardsSection(agentsText);
62
+ if (projectSection === undefined) {
63
+ return [
64
+ {
65
+ standard: "21",
66
+ message: `AGENTS.md has no ${SECTION_START} and ${SECTION_END} markers. Copy the Code standards section from the template, markers included`,
67
+ page: PAGE,
68
+ },
69
+ ];
70
+ }
71
+ const templateSection = readStandardsSection(
72
+ readTextFile({
73
+ projectDirectory: templatesDirectory,
74
+ filePath: "AGENTS.md",
75
+ }) ?? "",
76
+ );
77
+ if (projectSection === templateSection) {
78
+ return [];
79
+ }
80
+ return [
81
+ {
82
+ standard: "21",
83
+ message:
84
+ "The Code standards section of AGENTS.md differs from the template. Copy it again, and record any project exception in docs/development/coding-standards.md instead",
85
+ page: PAGE,
86
+ },
87
+ ];
88
+ };
89
+
90
+ const checkSkills = ({ projectDirectory, templatesDirectory }) => {
91
+ const skillNames = readdirSync(
92
+ path.join(templatesDirectory, "skills"),
93
+ );
94
+ const findings = [];
95
+ for (const folder of SKILL_FOLDERS) {
96
+ for (const skillName of skillNames) {
97
+ const template = readTextFile({
98
+ projectDirectory: templatesDirectory,
99
+ filePath: path.join("skills", skillName),
100
+ });
101
+ const projectSkill = readTextFile({
102
+ projectDirectory,
103
+ filePath: path.join(folder, skillName),
104
+ });
105
+ if (projectSkill === undefined) {
106
+ findings.push({
107
+ standard: "21",
108
+ message: `${folder}/${skillName} is missing`,
109
+ page: "docs/Standards/agent-skills.md",
110
+ });
111
+ continue;
112
+ }
113
+ if (projectSkill.trimEnd() !== template?.trimEnd()) {
114
+ findings.push({
115
+ standard: "21",
116
+ message: `${folder}/${skillName} differs from the template`,
117
+ page: "docs/Standards/agent-skills.md",
118
+ });
119
+ }
120
+ }
121
+ }
122
+ return findings;
123
+ };
124
+
125
+ export const checkAgentFiles = ({
126
+ projectDirectory,
127
+ templatesDirectory,
128
+ packageMajorVersion,
129
+ }) => {
130
+ const agentsText = readTextFile({
131
+ projectDirectory,
132
+ filePath: "AGENTS.md",
133
+ });
134
+ if (agentsText === undefined) {
135
+ return [
136
+ {
137
+ standard: "21",
138
+ message: "AGENTS.md is missing. Follow Setup",
139
+ page: "docs/Guides/setup.md",
140
+ },
141
+ ];
142
+ }
143
+ return [
144
+ ...checkVersion({ agentsText, packageMajorVersion }),
145
+ ...checkStandardsSection({ agentsText, templatesDirectory }),
146
+ ...checkSkills({ projectDirectory, templatesDirectory }),
147
+ ];
148
+ };
@@ -0,0 +1,129 @@
1
+ // Standards 4 and 15: every function and component has a test file,
2
+ // and every components/ui/ component is on the Design System list.
3
+ import path from "node:path";
4
+
5
+ import { readTextFile } from "./projectFiles.mjs";
6
+
7
+ const SOURCE_FOLDERS = [
8
+ "app/",
9
+ "components/",
10
+ "hooks/",
11
+ "lib/",
12
+ "services/",
13
+ "utils/",
14
+ ];
15
+ const SOURCE_FILE_PATTERN = /\.(ts|tsx|js|jsx)$/;
16
+ // Files that hold no function or component of their own.
17
+ const NO_TEST_NEEDED_PATTERN =
18
+ /(\.test\.|\.stories\.|\.d\.ts$|\.config\.|\.types\.tsx?$|(^|\/)(index|types|constants)\.tsx?$)/;
19
+ // A file needs a test when it exports a function or a component.
20
+ // A file of data only, such as an illustration's points, does not.
21
+ const EXPORTS_FUNCTION_PATTERN =
22
+ /export\s+(default\s+)?(async\s+)?function\b|export\s+const\s+\w+\s*(:[^=]+)?=\s*(async\s+)?(\([^)]*\)|\w+)\s*(:[^=]+)?=>/;
23
+ const UI_FOLDER_PATTERN = /^components\/ui\/([^/]+)\//;
24
+ const LISTED_COMPONENT_PATTERN = /^\|\s*\d+\s*\|\s*\*\*(.+?)\*\*/;
25
+
26
+ // "Spacer / Divider" → ["spacerdivider", "spacer", "divider"]
27
+ const toComparableNames = (componentName) => {
28
+ const parts = componentName.split("/");
29
+ return [componentName, ...parts].map((name) =>
30
+ name.toLowerCase().replaceAll(/[^a-z0-9]/g, ""),
31
+ );
32
+ };
33
+
34
+ const toComparableName = (folderName) =>
35
+ folderName.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
36
+
37
+ const readListedComponents = ({ standardsDocsDirectory }) => {
38
+ const markdown =
39
+ readTextFile({
40
+ projectDirectory: standardsDocsDirectory,
41
+ filePath: "design-system-components.md",
42
+ }) ?? "";
43
+ return new Set(
44
+ markdown
45
+ .split("\n")
46
+ .map((line) => LISTED_COMPONENT_PATTERN.exec(line)?.[1])
47
+ .filter(Boolean)
48
+ .flatMap((componentName) => toComparableNames(componentName)),
49
+ );
50
+ };
51
+
52
+ const checkUiComponents = ({
53
+ projectFiles,
54
+ standardsDocsDirectory,
55
+ recordedExceptions,
56
+ }) => {
57
+ const listedComponents = readListedComponents({
58
+ standardsDocsDirectory,
59
+ });
60
+ const recordedComponents = toComparableName(
61
+ recordedExceptions.componentsText,
62
+ );
63
+ const uiFolders = new Set(
64
+ projectFiles
65
+ .map((filePath) => UI_FOLDER_PATTERN.exec(filePath)?.[1])
66
+ .filter(Boolean),
67
+ );
68
+ return [...uiFolders]
69
+ .filter(
70
+ (folder) =>
71
+ !listedComponents.has(toComparableName(folder)) &&
72
+ !recordedComponents.includes(toComparableName(folder)),
73
+ )
74
+ .map((folder) => ({
75
+ standard: "15",
76
+ message: `components/ui/${folder} is not on the Design System Components list. If it takes everything through props, record it under "Components for the standards" in docs/development/coding-standards.md; otherwise move it out of components/ui/`,
77
+ page: "docs/design-system-components.md",
78
+ }));
79
+ };
80
+
81
+ const isSourceFile = (filePath) =>
82
+ SOURCE_FOLDERS.some((folder) => filePath.startsWith(folder)) &&
83
+ SOURCE_FILE_PATTERN.test(filePath) &&
84
+ !NO_TEST_NEEDED_PATTERN.test(filePath) &&
85
+ !filePath.startsWith("lib/constants/") &&
86
+ !filePath.startsWith("lib/types/");
87
+
88
+ const findTestFile = ({ filePath, projectFileSet }) => {
89
+ const { dir, name } = path.posix.parse(filePath);
90
+ return [".ts", ".tsx", ".js", ".jsx"].some((extension) =>
91
+ projectFileSet.has(
92
+ path.posix.join(dir, `${name}.test${extension}`),
93
+ ),
94
+ );
95
+ };
96
+
97
+ const doesExportFunction = ({ projectDirectory, filePath }) =>
98
+ EXPORTS_FUNCTION_PATTERN.test(
99
+ readTextFile({ projectDirectory, filePath }) ?? "",
100
+ );
101
+
102
+ const checkTestFiles = ({ projectDirectory, projectFiles }) => {
103
+ const projectFileSet = new Set(projectFiles);
104
+ return projectFiles
105
+ .filter((filePath) => isSourceFile(filePath))
106
+ .filter((filePath) =>
107
+ doesExportFunction({ projectDirectory, filePath }),
108
+ )
109
+ .filter((filePath) => !findTestFile({ filePath, projectFileSet }))
110
+ .map((filePath) => ({
111
+ standard: "4",
112
+ message: `${filePath} has no test file beside it`,
113
+ page: "docs/Standards/readable-code.md#every-function-and-component-has-a-test-file",
114
+ }));
115
+ };
116
+
117
+ export const checkComponents = ({
118
+ projectDirectory,
119
+ projectFiles,
120
+ standardsDocsDirectory,
121
+ recordedExceptions,
122
+ }) => [
123
+ ...checkUiComponents({
124
+ projectFiles,
125
+ standardsDocsDirectory,
126
+ recordedExceptions,
127
+ }),
128
+ ...checkTestFiles({ projectDirectory, projectFiles }),
129
+ ];
@@ -0,0 +1,230 @@
1
+ // Standards 6 to 10: the copied config files match the templates.
2
+ import path from "node:path";
3
+
4
+ import { readTextFile } from "./projectFiles.mjs";
5
+
6
+ const ESLINT_TEMPLATE_NAMES = [
7
+ "base",
8
+ "typescript",
9
+ "react",
10
+ "nextjs",
11
+ ];
12
+ const STYLELINT_TEMPLATE_NAMES = ["css", "scss"];
13
+ const FORMAT_SCRIPTS = {
14
+ format:
15
+ "git ls-files -z --cached --others --exclude-standard | xargs -0 prettier --write --ignore-unknown --no-error-on-unmatched-pattern",
16
+ "format:check":
17
+ "git ls-files -z --cached --others --exclude-standard | xargs -0 prettier --check --ignore-unknown --no-error-on-unmatched-pattern",
18
+ };
19
+ // Lines a project is told to change in prettier.config.mjs: the
20
+ // stylesheet path, and the plugin lines in a project without Tailwind.
21
+ const PRETTIER_PROJECT_LINES = /tailwindStylesheet|plugins:/;
22
+
23
+ // Comments and spacing may be rewrapped by the project's own
24
+ // formatting; only the settings themselves have to match.
25
+ const normaliseSettings = (text) =>
26
+ text
27
+ .replaceAll("\r\n", "\n")
28
+ .replaceAll(/\/\*[\s\S]*?\*\//g, "")
29
+ .replaceAll(/^\s*\/\/.*$/gm, "")
30
+ .replaceAll(/\s+/g, " ")
31
+ .trim();
32
+
33
+ const readTemplate = ({ templatesDirectory, filePath }) =>
34
+ readTextFile({ projectDirectory: templatesDirectory, filePath });
35
+
36
+ const matchesAnyTemplate = ({
37
+ projectText,
38
+ templatesDirectory,
39
+ templatePaths,
40
+ }) =>
41
+ templatePaths.some(
42
+ (templatePath) =>
43
+ normaliseSettings(
44
+ readTemplate({
45
+ templatesDirectory,
46
+ filePath: templatePath,
47
+ }) ?? "",
48
+ ) === normaliseSettings(projectText),
49
+ );
50
+
51
+ const checkEslint = ({ projectDirectory, templatesDirectory }) => {
52
+ const config = readTextFile({
53
+ projectDirectory,
54
+ filePath: "eslint.config.mjs",
55
+ });
56
+ if (config === undefined) {
57
+ return [
58
+ { standard: "6", message: "eslint.config.mjs is missing" },
59
+ ];
60
+ }
61
+ const isTemplateCopy = matchesAnyTemplate({
62
+ projectText: config,
63
+ templatesDirectory,
64
+ templatePaths: ESLINT_TEMPLATE_NAMES.map((name) =>
65
+ path.join("eslint", name, "eslint.config.mjs"),
66
+ ),
67
+ });
68
+ const findings = [];
69
+ if (!isTemplateCopy) {
70
+ findings.push({
71
+ standard: "6",
72
+ message:
73
+ "eslint.config.mjs differs from every template. Copy the template over it, and move the project's own rules into eslint.overrides.mjs",
74
+ page: "docs/Standards/eslint.md#project-specific-overrides",
75
+ });
76
+ }
77
+ const overrides = readTextFile({
78
+ projectDirectory,
79
+ filePath: "eslint.overrides.mjs",
80
+ });
81
+ if (overrides === undefined) {
82
+ findings.push({
83
+ standard: "6",
84
+ message:
85
+ "eslint.overrides.mjs is missing. Copy it from static/templates/eslint.overrides.mjs",
86
+ page: "docs/Standards/eslint.md#project-specific-overrides",
87
+ });
88
+ }
89
+ return findings;
90
+ };
91
+
92
+ const withoutProjectLines = (text) =>
93
+ normaliseSettings(
94
+ text
95
+ .split("\n")
96
+ .filter((line) => !PRETTIER_PROJECT_LINES.test(line))
97
+ .join("\n"),
98
+ );
99
+
100
+ const checkPrettier = ({ projectDirectory, templatesDirectory }) => {
101
+ const config = readTextFile({
102
+ projectDirectory,
103
+ filePath: "prettier.config.mjs",
104
+ });
105
+ if (config === undefined) {
106
+ return [
107
+ { standard: "7", message: "prettier.config.mjs is missing" },
108
+ ];
109
+ }
110
+ const findings = [];
111
+ const template =
112
+ readTemplate({
113
+ templatesDirectory,
114
+ filePath: "prettier.config.mjs",
115
+ }) ?? "";
116
+ if (withoutProjectLines(config) !== withoutProjectLines(template)) {
117
+ findings.push({
118
+ standard: "7",
119
+ message: "prettier.config.mjs differs from the template",
120
+ page: "docs/Standards/prettier.md",
121
+ });
122
+ }
123
+ const packageText =
124
+ readTextFile({ projectDirectory, filePath: "package.json" }) ??
125
+ "{}";
126
+ const scripts = JSON.parse(packageText).scripts ?? {};
127
+ for (const [name, command] of Object.entries(FORMAT_SCRIPTS)) {
128
+ if (scripts[name] !== command) {
129
+ findings.push({
130
+ standard: "7",
131
+ message: `The "${name}" script in package.json is not the standard one`,
132
+ page: "docs/Standards/prettier.md#usage",
133
+ });
134
+ }
135
+ }
136
+ return findings;
137
+ };
138
+
139
+ const checkExactCopy = ({
140
+ projectDirectory,
141
+ templatesDirectory,
142
+ filePath,
143
+ standard,
144
+ page,
145
+ }) => {
146
+ const projectText = readTextFile({ projectDirectory, filePath });
147
+ if (projectText === undefined) {
148
+ return [{ standard, message: `${filePath} is missing`, page }];
149
+ }
150
+ const isCopy = matchesAnyTemplate({
151
+ projectText,
152
+ templatesDirectory,
153
+ templatePaths: [filePath],
154
+ });
155
+ return isCopy
156
+ ? []
157
+ : [
158
+ {
159
+ standard,
160
+ message: `${filePath} differs from the template`,
161
+ page,
162
+ },
163
+ ];
164
+ };
165
+
166
+ const checkStylelint = ({ projectDirectory, templatesDirectory }) => {
167
+ const config = readTextFile({
168
+ projectDirectory,
169
+ filePath: "stylelint.config.mjs",
170
+ });
171
+ // Stylelint is only for projects with hand-written CSS.
172
+ if (config === undefined) {
173
+ return [];
174
+ }
175
+ const isCopy = matchesAnyTemplate({
176
+ projectText: config,
177
+ templatesDirectory,
178
+ templatePaths: STYLELINT_TEMPLATE_NAMES.map((name) =>
179
+ path.join("stylelint", name, "stylelint.config.mjs"),
180
+ ),
181
+ });
182
+ return isCopy
183
+ ? []
184
+ : [
185
+ {
186
+ standard: "8",
187
+ message: "stylelint.config.mjs differs from both templates",
188
+ page: "docs/Standards/stylelint.md",
189
+ },
190
+ ];
191
+ };
192
+
193
+ export const checkConfigFiles = ({
194
+ projectDirectory,
195
+ templatesDirectory,
196
+ }) => {
197
+ const nodeVersion = readTextFile({
198
+ projectDirectory,
199
+ filePath: ".nvmrc",
200
+ });
201
+ return [
202
+ ...checkEslint({ projectDirectory, templatesDirectory }),
203
+ ...checkPrettier({ projectDirectory, templatesDirectory }),
204
+ ...checkStylelint({ projectDirectory, templatesDirectory }),
205
+ ...checkExactCopy({
206
+ projectDirectory,
207
+ templatesDirectory,
208
+ filePath: ".editorconfig",
209
+ standard: "9",
210
+ page: "docs/Standards/editorconfig.md",
211
+ }),
212
+ ...checkExactCopy({
213
+ projectDirectory,
214
+ templatesDirectory,
215
+ filePath: ".envrc",
216
+ standard: "10",
217
+ page: "docs/Standards/direnv.mdx",
218
+ }),
219
+ // The Node version itself is the project's choice.
220
+ ...(nodeVersion === undefined
221
+ ? [
222
+ {
223
+ standard: "10",
224
+ message: ".nvmrc is missing",
225
+ page: "docs/Standards/direnv.mdx",
226
+ },
227
+ ]
228
+ : []),
229
+ ];
230
+ };
@@ -0,0 +1,86 @@
1
+ // Standard 18: every doc is a Decision Doc in the standard format.
2
+ import path from "node:path";
3
+
4
+ import { readTextFile } from "./projectFiles.mjs";
5
+
6
+ const DOC_PATTERN = /^docs\/(?!assets\/).+\.mdx?$/;
7
+ const TITLE_PATTERN = /^# (.+) — (.+)$/;
8
+ const STATUS_PATTERN =
9
+ /^\*\*Status:\*\* (Not started|Under evaluation|Current plan|Decided) · \*\*Updated:\*\* /m;
10
+ const REQUIRED_SECTIONS = ["Decision", "Why", "Related"];
11
+ const CODE_FENCE = "```";
12
+ const PAGE = "docs/Standards/documentation.md#-the-doc-format";
13
+
14
+ // Headings inside code blocks are examples, not headings.
15
+ const readTopHeadings = (markdown) => {
16
+ const headings = [];
17
+ // eslint-disable-next-line no-restricted-syntax -- flips at each code fence while reading line by line
18
+ let isInCodeBlock = false;
19
+ for (const line of markdown.split("\n")) {
20
+ if (line.startsWith(CODE_FENCE)) {
21
+ isInCodeBlock = !isInCodeBlock;
22
+ continue;
23
+ }
24
+ if (!isInCodeBlock && line.startsWith("# ")) {
25
+ headings.push(line.trimEnd());
26
+ }
27
+ }
28
+ return headings;
29
+ };
30
+
31
+ const toKebabCase = (text) =>
32
+ text
33
+ .toLowerCase()
34
+ .replaceAll(/[^a-z0-9]+/g, "-")
35
+ .replaceAll(/^-|-$/g, "");
36
+
37
+ const checkTitle = ({ filePath, headings }) => {
38
+ if (headings.length !== 1) {
39
+ return [
40
+ `has ${headings.length} "#" headings. A doc has exactly one, its title`,
41
+ ];
42
+ }
43
+ const match = TITLE_PATTERN.exec(headings[0]);
44
+ if (!match) {
45
+ return [
46
+ 'has a title that is not in "Group — Menu item" form, such as "# Overview — What Is It"',
47
+ ];
48
+ }
49
+ const expectedFileName = toKebabCase(match[2]);
50
+ const fileName = path.posix.parse(filePath).name;
51
+ return fileName === expectedFileName
52
+ ? []
53
+ : [
54
+ `is named ${fileName}, but its menu item "${match[2]}" makes it ${expectedFileName}`,
55
+ ];
56
+ };
57
+
58
+ const checkDocument = ({ projectDirectory, filePath }) => {
59
+ const markdown = readTextFile({ projectDirectory, filePath }) ?? "";
60
+ const problems = [
61
+ ...checkTitle({ filePath, headings: readTopHeadings(markdown) }),
62
+ ];
63
+ if (!STATUS_PATTERN.test(markdown)) {
64
+ problems.push(
65
+ "has no **Status:** · **Updated:** line with a standard status",
66
+ );
67
+ }
68
+ const missingSections = REQUIRED_SECTIONS.filter(
69
+ (section) => !markdown.includes(`\n## ${section}\n`),
70
+ );
71
+ if (missingSections.length > 0) {
72
+ problems.push(`is missing ## ${missingSections.join(", ## ")}`);
73
+ }
74
+ return problems.map((problem) => ({
75
+ standard: "18",
76
+ message: `${filePath} ${problem}`,
77
+ page: PAGE,
78
+ }));
79
+ };
80
+
81
+ export const checkDocs = ({ projectDirectory, projectFiles }) =>
82
+ projectFiles
83
+ .filter((filePath) => DOC_PATTERN.test(filePath))
84
+ .flatMap((filePath) =>
85
+ checkDocument({ projectDirectory, filePath }),
86
+ );
@@ -0,0 +1,96 @@
1
+ // Standards 12.1 and 18: the files every project has.
2
+ import { readdirSync, statSync } from "node:fs";
3
+ import path from "node:path";
4
+
5
+ import { CODING_STANDARDS_PATH } from "./projectFiles.mjs";
6
+
7
+ const CONSTANTS_FILES = [
8
+ "lib/constants/index.ts",
9
+ "lib/constants/routes.ts",
10
+ "lib/constants/strings.ts",
11
+ "lib/constants/numbers.ts",
12
+ ];
13
+ // Setup renames this file after the project: what-is-launchpad.md.
14
+ const RENAMED_OVERVIEW_PATH = "overview/what-is-it.md";
15
+ const RENAMED_OVERVIEW_PATTERN = /^docs\/overview\/what-is-.+\.md$/;
16
+ const COMPONENT_CONSTANTS_PATTERN = /(^|\/)constants\.tsx?$/;
17
+
18
+ const listTemplateDocs = ({ directory, prefix = "" }) =>
19
+ readdirSync(directory).flatMap((entry) => {
20
+ const entryPath = path.join(directory, entry);
21
+ const relativePath = path.posix.join(prefix, entry);
22
+ return statSync(entryPath).isDirectory()
23
+ ? listTemplateDocs({
24
+ directory: entryPath,
25
+ prefix: relativePath,
26
+ })
27
+ : [relativePath];
28
+ });
29
+
30
+ const checkDocsFiles = ({ templatesDirectory, projectFiles }) => {
31
+ const projectFileSet = new Set(projectFiles);
32
+ const templateDocuments = listTemplateDocs({
33
+ directory: path.join(templatesDirectory, "docs"),
34
+ });
35
+ const isOverviewRenamed = projectFiles.some((filePath) =>
36
+ RENAMED_OVERVIEW_PATTERN.test(filePath),
37
+ );
38
+ return templateDocuments
39
+ .filter(
40
+ (templateDocument) =>
41
+ !projectFileSet.has(`docs/${templateDocument}`),
42
+ )
43
+ .filter(
44
+ (templateDocument) =>
45
+ !(
46
+ templateDocument === RENAMED_OVERVIEW_PATH &&
47
+ isOverviewRenamed
48
+ ),
49
+ )
50
+ .map((templateDocument) => ({
51
+ standard: "18",
52
+ message: `docs/${templateDocument} is missing. Copy it from the doc templates`,
53
+ page: "docs/Standards/documentation.md#every-file-exists-from-the-start",
54
+ }));
55
+ };
56
+
57
+ const checkConstantsFiles = ({ projectFiles }) => {
58
+ const projectFileSet = new Set(projectFiles);
59
+ const missing = CONSTANTS_FILES.filter(
60
+ (filePath) => !projectFileSet.has(filePath),
61
+ ).map((filePath) => ({
62
+ standard: "12.1",
63
+ message: `${filePath} is missing`,
64
+ page: "docs/Structure/folder-structure.md#constants",
65
+ }));
66
+ const componentConstants = projectFiles
67
+ .filter((filePath) => !filePath.startsWith("lib/constants/"))
68
+ .filter((filePath) => !filePath.startsWith("node_modules/"))
69
+ .filter((filePath) => COMPONENT_CONSTANTS_PATTERN.test(filePath))
70
+ .map((filePath) => ({
71
+ standard: "12.1",
72
+ message: `${filePath}: there is no component-level constants file. Move its values into r, s and numbers.ts in lib/constants/`,
73
+ page: "docs/Structure/folder-structure.md#constants",
74
+ }));
75
+ return [...missing, ...componentConstants];
76
+ };
77
+
78
+ export const checkRequiredFiles = ({
79
+ templatesDirectory,
80
+ projectFiles,
81
+ }) => {
82
+ const codingStandards = projectFiles.includes(CODING_STANDARDS_PATH)
83
+ ? []
84
+ : [
85
+ {
86
+ standard: "21",
87
+ message: `${CODING_STANDARDS_PATH} is missing. It records the standards this project skips or changes`,
88
+ page: "docs/Guides/setup.md#3-agree-the-standards",
89
+ },
90
+ ];
91
+ return [
92
+ ...codingStandards,
93
+ ...checkDocsFiles({ templatesDirectory, projectFiles }),
94
+ ...checkConstantsFiles({ projectFiles }),
95
+ ];
96
+ };