Skip to content

Commit 7e4567a

Browse files
committed
Better linter
1 parent 25af025 commit 7e4567a

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

docs/typescriptlang/id/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const indexCopy = {
22
index_headline: "<bold>JavaScript dengan Tipe dalam skala apapun.</bold>",
3-
index_byline: "TypeScript memperluas JavaScript dengan menambahkan tipe.",
3+
index_byline: `TypeScript ${""}}memperluas JavaScript dengan menambahkan tipe.`,
44
index_summary:
55
"Dengan memahami JavaScript, TypeScript menghemat waktu Anda dalam menangkap galat dan memberikan perbaikan sebelum Anda menjalankan kode.",
66
index_locations:

docs/typescriptlang/pl/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const indexCopy = {
2-
index_headline: "<bold>Typowany JavaScript w każdej skali.</bold>",
2+
index_headline: `<bold>${""}}Typowany JavaScript w każdej skali.</bold>`,
33
index_byline: "TypeScript rozszerza JavaScript poprzez dodatek typów.",
44
index_summary:
55
"TypeScript rozumie JavaScript, przez co oszczędzaj Twój czas wyłapując błędy i dostarczając rozwiązania problemów zanim uruchomisz kod.",

scripts/lint.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ function lintTSLanguageFile(file) {
186186
errors.push( new Error("A root language import can only include imports and an export called 'lang' "));
187187
}
188188

189+
if (lastStatementIsDeclaration) {
190+
/** @type {import("typescript").VariableDeclarationList} */
191+
// @ts-ignore
192+
const declarationList = notImportStatements[0].declarationList
193+
194+
const declaration = declarationList.declarations[0]
195+
if (!declaration.initializer) errors.push( new Error(`Something is off with the export in this file`));
196+
197+
/** @type {import("typescript").CallExpression} */
198+
// @ts-ignore
199+
const callExpression = declaration.initializer.expression
200+
if (callExpression.getText(sourceFile) !== "defineMessages") errors.push( new Error(`The export needs to call define messages`));
201+
202+
/** @type {import("typescript").ObjectLiteralExpression} */
203+
// @ts-ignore
204+
const arg0 = declaration.initializer.arguments[0]
205+
arg0.properties.forEach(p => {
206+
if (p.kind !== 290) errors.push( new Error(`You can only have spreads (...) in the export`));
207+
})
208+
}
209+
189210
sourceFile.statements.forEach(s => {
190211
if (!ts.isImportDeclaration(s)) return
191212
if (!s.importClause) errors.push( new Error(`The import ${s.moduleSpecifier.getText(sourceFile)} is not importing an object`));
@@ -196,7 +217,6 @@ function lintTSLanguageFile(file) {
196217
if (!allowed.includes(specifier) && !specifier.startsWith('".')) {
197218
errors.push( new Error(`The import ${specifier} is not allowlisted ([${allowed.join(", ")}]) nor relative`));
198219
}
199-
200220
})
201221

202222
} else {
@@ -211,6 +231,32 @@ function lintTSLanguageFile(file) {
211231
if (notDeclarationList) {
212232
errors.push(new Error("TS files should only look like: `export const somethingCopy = { ... }` "))
213233
}
234+
// @ts-ignore
235+
const lastStatement = sourceFile.statements[0].declarationList
236+
if (!ts.isVariableDeclarationList(lastStatement)) {
237+
errors.push(new Error("TS files should only look like: `export const somethingCopy = { ... }` "))
238+
} else {
239+
/** @type {import("typescript").ObjectLiteralExpression} */
240+
// @ts-ignore
241+
const init = lastStatement.declarations[0].initializer
242+
if (!init) {
243+
errors.push(new Error("Something is off in the const in that file"))
244+
} else {
245+
init.properties.forEach(prop => {
246+
/** @type {import("typescript").PropertyAssignment} */
247+
// @ts-ignore
248+
const init = prop.initializer
249+
if (init.kind !== 10 && init.kind !== 14) {
250+
if (init.kind === 218) {
251+
errors.push(new Error(`The template string at ${prop.name.getText(sourceFile)} can't have evaluated code ( no \${} allowed )`))
252+
} else {
253+
errors.push(new Error(`The value at ${prop.name.getText(sourceFile)} isn't a string`))
254+
}
255+
}
256+
});
257+
}
258+
// declarationList.declarations[0]
259+
}
214260
}
215261

216262

0 commit comments

Comments
 (0)