Skip to content

Commit 25af025

Browse files
committed
Improve CI
1 parent 24b9414 commit 25af025

File tree

9 files changed

+114
-43
lines changed

9 files changed

+114
-43
lines changed

docs/typescriptlang/es/nav.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { navCopy as enNavCopy } from "../en/nav"
2-
31
export const navCopy = {
4-
...enNavCopy,
52
skip_to_content: "Saltar al contenido principal",
63
nav_documentation: "Documentación",
74
nav_documentation_short: "Docs",

docs/typescriptlang/ja/documentation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { docCopy as enDocCopy } from "../en/documentation"
2-
31
export const docCopy = {
4-
...enDocCopy,
52
doc_layout_title: "TypeScript学習の第一歩",
63
doc_layout_description:
74
"TypeScriptスタータープロジェクトを見つけましょう: AngularからReact、Node.js、そしてCLIまで",

docs/typescriptlang/ja/nav.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { navCopy as enNavCopy } from "../en/nav"
2-
31
export const navCopy = {
4-
...enNavCopy,
52
skip_to_content: "スキップしてメインコンテンツに進む",
63
nav_documentation: "ドキュメント",
74
nav_documentation_short: "ドキュメント",

docs/typescriptlang/vo/nav.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { navCopy as enNavCopy } from "../en/nav"
2-
31
export const navCopy = {
4-
...enNavCopy,
52
skip_to_content: "Sk1p t0 main Con7ent",
63
nav_documentation: "D0cumentation",
74
nav_documentation_short: "Docs",

docs/typescriptlang/zh/zh.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { indexCopy } from "./index"
88
import { comCopy } from "./community"
99
import { handbookCopy } from "./handbook"
1010

11-
export const messages = {
11+
export const lang = defineMessages({
1212
...englishMessages,
1313
...navCopy,
1414
...docCopy,
@@ -17,6 +17,4 @@ export const messages = {
1717
...playCopy,
1818
...comCopy,
1919
...handbookCopy,
20-
}
21-
22-
export const lang = defineMessages(messages)
20+
})

localize.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,16 @@
1616
{ "name": "TSConfig Reference", "from": "packages/tsconfig-reference/copy/", "to": "docs/tsconfig" },
1717
{ "name": "Website copy", "from": "packages/typescriptlang-org/src/copy/", "to": "docs/typescriptlang" },
1818
{ "name": "Documentation", "from": "packages/documentation/copy/", "to": "docs/documentation" }
19-
]
19+
],
20+
"validate": {
21+
"ignoreFiles": [
22+
"docs/typescriptlang/es/es.ts",
23+
"docs/typescriptlang/id/id.ts",
24+
"docs/typescriptlang/ja/ja.ts",
25+
"docs/typescriptlang/pl/pl.ts",
26+
"docs/typescriptlang/pt/pt.ts",
27+
"docs/typescriptlang/vo/vo.ts",
28+
"docs/typescriptlang/zh/zh.ts"
29+
]
30+
}
2031
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"chalk": "^4.1.0",
2222
"gatsby-remark-shiki-twoslash": "^0.7.0",
2323
"gray-matter": "^4.0.2",
24+
"preact": "^10.5.12",
2425
"remark": "^13.0.0",
2526
"typescript": "^4.1.3"
2627
}

scripts/lint.js

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const chalk = require("chalk");
1414
const { readFileSync, watch } = require("fs");
15-
const { join, basename, sep } = require("path");
15+
const { join, basename, sep, dirname } = require("path");
1616
const readline = require('readline')
1717

1818
const ts = require("typescript");
@@ -54,23 +54,23 @@ if (filterString === "--watch") {
5454
validateAtPaths(toValidate);
5555
}
5656

57-
/** @param {string[]} mdDocs */
58-
function validateAtPaths(mdDocs) {
57+
/** @param {string[]} docs */
58+
function validateAtPaths(docs) {
5959
let errorReports = [];
6060

61-
mdDocs.forEach((docAbsPath, i) => {
61+
docs.forEach((docAbsPath, i) => {
6262
const docPath = docAbsPath;
6363
const filename = basename(docPath);
6464

6565
let lintFunc = undefined;
6666

67-
if (docAbsPath.endsWith(".ts")) {
67+
if (docAbsPath.includes("typescriptlang") && docAbsPath.endsWith(".ts")) {
6868
lintFunc = lintTSLanguageFile;
6969
} else if (docAbsPath.endsWith(".md")) {
7070
lintFunc = lintMarkdownFile;
7171
}
7272

73-
const isLast = i === mdDocs.length - 1;
73+
const isLast = i === docs.length - 1;
7474
const suffix = isLast ? "" : ", ";
7575

7676
if (!lintFunc) {
@@ -130,15 +130,15 @@ function lintMarkdownFile(docPath) {
130130
const lang = relativePath.split(sep)[2];
131131

132132
if (docType === "documentation") {
133-
if (!greyMD.data.display) {
133+
if (!greyMD.data.title) {
134134
errors.push(new Error("Did not have a 'display' property in the YML header"));
135135
}
136136

137137
if (greyMD.data.layout !== "docs") {
138138
errors.push(new Error("Expected 'layout: docs' in the YML header"));
139139
}
140140

141-
if (greyMD.data.permalink.startsWith("/" + lang)) {
141+
if (!greyMD.data.permalink.startsWith("/" + lang)) {
142142
errors.push(new Error(`Expected 'permalink:' in the YML header to start with '/${lang}'`));
143143
}
144144
} else if (docType === "tsconfig") {
@@ -158,7 +158,7 @@ function lintMarkdownFile(docPath) {
158158

159159
/** @param {string} file */
160160
function lintTSLanguageFile(file) {
161-
/** @type {{ path: string, error: Error }[]} */
161+
/** @type {Error[]} */
162162
const errors = [];
163163

164164
const content = readFileSync(file, "utf8");
@@ -170,22 +170,50 @@ function lintTSLanguageFile(file) {
170170
ts.ScriptKind.TS
171171
);
172172

173-
const tooManyStatements = sourceFile.statements.length > 1;
174-
const notDeclarationList = sourceFile.statements[0].kind !== 232;
173+
174+
const filename = basename(file, ".ts")
175+
const lastDir = dirname(file).split(sep).pop()
176+
177+
const isRootImport = filename === lastDir
178+
if (isRootImport) {
179+
// This is the import for the language which pulls in all the existing messages
180+
//
181+
const notImportStatements = sourceFile.statements.filter(f => f.kind !== 261)
182+
const lastStatementIsDeclaration = sourceFile.statements[0].kind !== 232;
183+
const onlyImportsAndOneExport = lastStatementIsDeclaration && notImportStatements.length === 1
184+
185+
if (!onlyImportsAndOneExport) {
186+
errors.push( new Error("A root language import can only include imports and an export called 'lang' "));
187+
}
175188

176-
if (tooManyStatements) {
177-
errors.push({
178-
path: file,
179-
error: new Error("TS files had more than one statement (e.g. more than `export const somethingCopy = { ... }` "),
180-
});
181-
}
189+
sourceFile.statements.forEach(s => {
190+
if (!ts.isImportDeclaration(s)) return
191+
if (!s.importClause) errors.push( new Error(`The import ${s.moduleSpecifier.getText(sourceFile)} is not importing an object`));
192+
193+
const allowed = ['"react-intl"']
194+
const specifier = s.moduleSpecifier.getText(sourceFile)
182195

183-
if (notDeclarationList) {
184-
errors.push({
185-
path: file,
186-
error: new Error("TS files should only look like: `export const somethingCopy = { ... }` "),
187-
});
196+
if (!allowed.includes(specifier) && !specifier.startsWith('".')) {
197+
errors.push( new Error(`The import ${specifier} is not allowlisted ([${allowed.join(", ")}]) nor relative`));
198+
}
199+
200+
})
201+
202+
} else {
203+
// This should just be a simple lint that it only has a declaration
204+
const tooManyStatements = sourceFile.statements.length > 1;
205+
const notDeclarationList = sourceFile.statements.length > 0 && sourceFile.statements[0].kind !== 232;
206+
207+
if (tooManyStatements) {
208+
errors.push( new Error("TS files had more than one statement (e.g. more than `export const somethingCopy = { ... }` "));
209+
}
210+
211+
if (notDeclarationList) {
212+
errors.push(new Error("TS files should only look like: `export const somethingCopy = { ... }` "))
213+
}
188214
}
189215

190-
return errors;
216+
217+
return errors.map((e) => ({ path: file, error: e }));
218+
191219
}

yarn.lock

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@
134134
unified-stream "^1.0.4"
135135

136136
"@oss-docs/sync@*":
137-
version "1.0.0"
138-
resolved "https://registry.yarnpkg.com/@oss-docs/sync/-/sync-1.0.0.tgz#72bf1a7bd7bee3dd543558d658e32f4928d45601"
139-
integrity sha512-rKPSkfKelzK0/oID5NdwMTQzIyIRpHF0DIU/dZG3vck4biXSU1o//3/rOiJodR/MaJR3j2GGklhCa4W5C1F8Ig==
137+
version "1.1.1"
138+
resolved "https://registry.yarnpkg.com/@oss-docs/sync/-/sync-1.1.1.tgz#fea457dabf8fd61f5170ae04de22026209c80b50"
139+
integrity sha512-AGTyz/tBaKkIu9CcIYLPF6EdLSwT/Wpu5r+sawLUmcJwNylKeobwBAhswjRw34U3b4TiNRZK1a5Szc70l+l1qg==
140140
dependencies:
141141
cachedir "^2.3.0"
142142
chalk "^4.1.0"
143143
cross-spawn "^7.0.1"
144144
gunzip-maybe "^1.4.1"
145+
micromatch "^4.0.2"
145146
mvdir "^1.0.21"
146147
tar-fs "^2.1.0"
147148
yargs "^16.2.0"
@@ -358,6 +359,13 @@ braces@^2.3.1:
358359
split-string "^3.0.2"
359360
to-regex "^3.0.1"
360361

362+
braces@^3.0.1:
363+
version "3.0.2"
364+
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
365+
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
366+
dependencies:
367+
fill-range "^7.0.1"
368+
361369
browserify-zlib@^0.1.4:
362370
version "0.1.4"
363371
resolved "https://registry.yarnpkg.com/browserify-zlib/-/browserify-zlib-0.1.4.tgz#bb35f8a519f600e0fa6b8485241c979d0141fb2d"
@@ -863,6 +871,13 @@ fill-range@^4.0.0:
863871
repeat-string "^1.6.1"
864872
to-regex-range "^2.1.0"
865873

874+
fill-range@^7.0.1:
875+
version "7.0.1"
876+
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
877+
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
878+
dependencies:
879+
to-regex-range "^5.0.1"
880+
866881
for-in@^1.0.2:
867882
version "1.0.2"
868883
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -1233,6 +1248,11 @@ is-number@^3.0.0:
12331248
dependencies:
12341249
kind-of "^3.0.2"
12351250

1251+
is-number@^7.0.0:
1252+
version "7.0.0"
1253+
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
1254+
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
1255+
12361256
is-plain-obj@^2.0.0:
12371257
version "2.1.0"
12381258
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287"
@@ -1637,6 +1657,14 @@ micromatch@^3.1.10:
16371657
snapdragon "^0.8.1"
16381658
to-regex "^3.0.2"
16391659

1660+
micromatch@^4.0.2:
1661+
version "4.0.2"
1662+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259"
1663+
integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==
1664+
dependencies:
1665+
braces "^3.0.1"
1666+
picomatch "^2.0.5"
1667+
16401668
16411669
version "1.45.0"
16421670
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.45.0.tgz#cceeda21ccd7c3a745eba2decd55d4b73e7879ea"
@@ -1880,6 +1908,11 @@ performance-now@^2.1.0:
18801908
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
18811909
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
18821910

1911+
picomatch@^2.0.5:
1912+
version "2.2.2"
1913+
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
1914+
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
1915+
18831916
pinpoint@^1.1.0:
18841917
version "1.1.0"
18851918
resolved "https://registry.yarnpkg.com/pinpoint/-/pinpoint-1.1.0.tgz#0cf7757a6977f1bf7f6a32207b709e377388e874"
@@ -1890,6 +1923,11 @@ posix-character-classes@^0.1.0:
18901923
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
18911924
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=
18921925

1926+
preact@^10.5.12:
1927+
version "10.5.12"
1928+
resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.12.tgz#6a8ee8bf40a695c505df9abebacd924e4dd37704"
1929+
integrity sha512-r6siDkuD36oszwlCkcqDJCAKBQxGoeEGytw2DGMD5A/GGdu5Tymw+N2OBXwvOLxg6d1FeY8MgMV3cc5aVQo4Cg==
1930+
18931931
prettyjson@^1.2.1:
18941932
version "1.2.1"
18951933
resolved "https://registry.yarnpkg.com/prettyjson/-/prettyjson-1.2.1.tgz#fcffab41d19cab4dfae5e575e64246619b12d289"
@@ -2458,6 +2496,13 @@ to-regex-range@^2.1.0:
24582496
is-number "^3.0.0"
24592497
repeat-string "^1.6.1"
24602498

2499+
to-regex-range@^5.0.1:
2500+
version "5.0.1"
2501+
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
2502+
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
2503+
dependencies:
2504+
is-number "^7.0.0"
2505+
24612506
to-regex@^3.0.1, to-regex@^3.0.2:
24622507
version "3.0.2"
24632508
resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce"

0 commit comments

Comments
 (0)