Bug 1962375 - Enable Prettier and file-perm linters for .ts files. r=zombie,linter-reviewers,profiler-reviewers,translations-reviewers,frontend-codestyle-reviewers,ahal,canaltinova

Differential Revision: https://phabricator.services.mozilla.com/D246622
This commit is contained in:
Mark Banner
2025-04-29 16:21:01 +00:00
parent 212ad7ecdf
commit 3cbf9cd24d
15 changed files with 207 additions and 113 deletions

View File

@@ -24,6 +24,9 @@ module.exports = [
// Include all js dot files.
"!.*.js",
// Exclude TypeScript files.
"*.ts",
// Ignore VSCode files
".vscode/",

View File

@@ -7,6 +7,10 @@
!*.sjs
!*.xhtml
!*.html
!*.ts
# Prettier currently fails to parse this.
toolkit/components/extensions/types/ext-tabs-base.d.ts
# Exclude xhtml/html test files.
**/test*/**/*.xhtml
@@ -18,9 +22,6 @@
!toolkit/content/tests/chrome/test_preferencesBindings_setting.html
!browser/components/preferences/tests/chrome/*.html
# Include Code Connect figma files
!toolkit/content/widgets/**/*.figma.ts
# This should be re-enabled in bug 1827456.
js/src/builtin
@@ -1108,6 +1109,9 @@ dom/encoding/test/file_utf16_le_bom.js
dom/base/test/file_js_cache.js
dom/serviceworkers/test/file_js_cache.js
# .ts files that aren't TypeScript
dom/media/test/hls/*.ts
# Intentional broken files
dom/base/test/file_js_cache_syntax_error.js
dom/base/test/jsmodules/test_scriptNotParsedAsModule.html
@@ -1698,5 +1702,6 @@ tools/@types/subs/
tools/browsertime/package.json
tools/browsertime/package-lock.json
tools/ts/error_list.json
tools/ts/test/baselines/
try_task_config.json
xpcom/idl-parser/xpidl/fixtures/xpctest.d.json

View File

@@ -245,7 +245,7 @@ declare namespace MockedExports {
preferredWidth?: number
) => Promise<FaviconData>;
// TS-TODO: Add the rest.
},
};
toURI: (uri: string | URL | nsIURI) => nsIURI;
};
};

View File

@@ -109,7 +109,7 @@ eslint:
- '**/*.sjs'
- '**/*.html'
- '**/*.xhtml'
- '**/*.xml'
- '**/*.ts'
- 'tools/lint/eslint.yml'
# Run when eslint or prettier policies change.
- '**/*eslintrc*'
@@ -551,6 +551,7 @@ file-perm:
- '**/*.rst'
- '**/*.svg'
- '**/*.toml'
- '**/*.ts'
- '**/*.ttf'
- '**/*.wasm'
- '**/*.webidl'

View File

@@ -2,13 +2,12 @@
* Types specific to toolkit/extensions code.
*/
declare global {
type BaseContext = import("ExtensionCommon.sys.mjs").BaseContext;
type ExtensionChild = import("ExtensionChild.sys.mjs").ExtensionChild;
type Extension = import("Extension.sys.mjs").Extension;
type callback = (...any) => any;
interface nsIDOMProcessChild {
interface nsIDOMProcessChild {
getActor(name: "ProcessConduits"): ProcessConduitsChild;
}
@@ -33,4 +32,4 @@ import { PointConduit, ProcessConduitsChild } from "ConduitsChild.sys.mjs";
import { ConduitAddress } from "ConduitsParent.sys.mjs";
type Conduit<Send> = PointConduit & { [s in `send${Items<Send>}`]: callback };
type Init<Send> = ConduitAddress & { send: Send; };
type Init<Send> = ConduitAddress & { send: Send };

View File

@@ -1,10 +1,24 @@
// Exports for all modules redirected here by a catch-all rule in tsconfig.json.
export var
AddonManager, AddonManagerPrivate, AddonSettings, AddonWrapper, AsyncShutdown,
ExtensionMenus, ExtensionProcessScript, ExtensionScriptingStore, ExtensionUserScripts,
NetUtil, E10SUtils, LightweightThemeManager, ServiceWorkerCleanUp, GeckoViewConnection,
GeckoViewWebExtension, IndexedDB, JSONFile, Log, UrlbarUtils, WebExtensionDescriptorActor;
export var AddonManager,
AddonManagerPrivate,
AddonSettings,
AddonWrapper,
AsyncShutdown,
ExtensionMenus,
ExtensionProcessScript,
ExtensionScriptingStore,
ExtensionUserScripts,
NetUtil,
E10SUtils,
LightweightThemeManager,
ServiceWorkerCleanUp,
GeckoViewConnection,
GeckoViewWebExtension,
IndexedDB,
JSONFile,
Log,
UrlbarUtils,
WebExtensionDescriptorActor;
/**
* A stub type for the "class" from EventEmitter.sys.mjs.

View File

@@ -1,9 +1,8 @@
export {};
declare global {
type Extension = import("resource://gre/modules/Extension.sys.mjs").Extension;
type DeferredTask = import("resource://gre/modules/DeferredTask.sys.mjs").DeferredTask;
type DeferredTask =
import("resource://gre/modules/DeferredTask.sys.mjs").DeferredTask;
}

View File

@@ -12,7 +12,7 @@
* For Remote Settings, the JSON details about the attachment.
*/
export interface Attachment {
// e.g. "2f7c0f7bbc...ca79f0850c4de",
// e.g. "2f7c0f7bbc...ca79f0850c4de",
hash: string;
// e.g. 5047568,
size: string;
@@ -183,37 +183,36 @@ export namespace Bergamot {
// Whether to include sentenceMappings or not. Alignments require
// sentenceMappings and are available irrespective of this option if
// `alignment=true`.
sentenceMappings: boolean
sentenceMappings: boolean;
}
}
/**
* The client to interact with RemoteSettings.
* See services/settings/RemoteSettingsClient.sys.mjs
*/
interface RemoteSettingsClient {
on: Function,
get: Function,
attachments: any,
on: Function;
get: Function;
attachments: any;
}
/**
* A single language model file.
*/
interface LanguageTranslationModelFile {
buffer: ArrayBuffer,
record: TranslationModelRecord,
buffer: ArrayBuffer;
record: TranslationModelRecord;
}
/**
* The data required to construct a Bergamot Translation Model.
*/
interface TranslationModelPayload {
sourceLanguage: string,
targetLanguage: string,
variant?: string,
languageModelFiles: LanguageTranslationModelFiles,
sourceLanguage: string;
targetLanguage: string;
variant?: string;
languageModelFiles: LanguageTranslationModelFiles;
}
/**
@@ -221,26 +220,26 @@ interface TranslationModelPayload {
*/
interface LanguageTranslationModelFiles {
// The machine learning language model.
model: LanguageTranslationModelFile,
model: LanguageTranslationModelFile;
// The lexical shortlist that limits possible output of the decoder and makes
// inference faster.
lex?: LanguageTranslationModelFile,
lex?: LanguageTranslationModelFile;
// A model that can generate a translation quality estimation.
qualityModel?: LanguageTranslationModelFile,
qualityModel?: LanguageTranslationModelFile;
// There is either a single vocab file:
vocab?: LanguageTranslationModelFile,
vocab?: LanguageTranslationModelFile;
// Or there are two:
srcvocab?: LanguageTranslationModelFile,
trgvocab?: LanguageTranslationModelFile,
srcvocab?: LanguageTranslationModelFile;
trgvocab?: LanguageTranslationModelFile;
}
/**
* This is the type that is generated when the models are loaded into wasm aligned memory.
*/
type LanguageTranslationModelFilesAligned = {
[K in keyof LanguageTranslationModelFiles]: Bergamot.AlignedMemory
[K in keyof LanguageTranslationModelFiles]: Bergamot.AlignedMemory;
};
/**
@@ -249,9 +248,9 @@ type LanguageTranslationModelFilesAligned = {
* and so the engine will be mocked.
*/
interface TranslationsEnginePayload {
bergamotWasmArrayBuffer: ArrayBuffer,
translationModelPayloads: TranslationModelPayload[]
isMocked: boolean,
bergamotWasmArrayBuffer: ArrayBuffer;
translationModelPayloads: TranslationModelPayload[];
isMocked: boolean;
}
/**
@@ -263,12 +262,12 @@ export type NodeVisibility = "in-viewport" | "out-of-viewport" | "hidden";
* Used to decide how to translate a page for full page translations.
*/
export interface LangTags {
isDocLangTagSupported: boolean,
docLangTag: string | null,
userLangTag: string | null,
htmlLangAttribute: string | null,
identifiedLangTag: string | null,
identifiedLangConfident?: boolean,
isDocLangTagSupported: boolean;
docLangTag: string | null;
userLangTag: string | null;
htmlLangAttribute: string | null;
identifiedLangTag: string | null;
identifiedLangConfident?: boolean;
}
/**
@@ -276,10 +275,10 @@ export interface LangTags {
* should be solvable by picking model variants, and pivoting through English.
*/
export interface LanguagePair {
sourceLanguage: string,
targetLanguage: string,
sourceVariant?: string,
targetVariant?: string
sourceLanguage: string;
targetLanguage: string;
sourceVariant?: string;
targetVariant?: string;
}
/**
@@ -288,16 +287,16 @@ export interface LanguagePair {
* needs and how they are resolved.
*/
export interface NonPivotLanguagePair {
sourceLanguage: string,
targetLanguage: string,
variant?: string,
sourceLanguage: string;
targetLanguage: string;
variant?: string;
}
export interface SupportedLanguage {
langTag: string,
langTagKey: string,
variant: string
displayName: string,
langTag: string;
langTagKey: string;
variant: string;
displayName: string;
}
/**
@@ -305,51 +304,99 @@ export interface SupportedLanguage {
* for translation language selection.
*/
export interface SupportedLanguages {
languagePairs: NonPivotLanguagePair[],
sourceLanguages: Array<SupportedLanguage>,
targetLanguages: Array<SupportedLanguage>,
languagePairs: NonPivotLanguagePair[];
sourceLanguages: Array<SupportedLanguage>;
targetLanguages: Array<SupportedLanguage>;
}
export type TranslationErrors = "engine-load-error";
export type SelectTranslationsPanelState =
// The panel is closed.
| { phase: "closed"; }
| { phase: "closed" }
// The panel is idle after successful initialization and ready to attempt translation.
| { phase: "idle"; sourceLanguage: string; targetLanguage: string, sourceText: string, }
| {
phase: "idle";
sourceLanguage: string;
targetLanguage: string;
sourceText: string;
}
// The language dropdown menus failed to populate upon opening the panel.
// This state contains all of the information for the try-again button to close and re-open the panel.
| { phase: "init-failure"; event: Event, screenX: number, screenY: number, sourceText: string, isTextSelected: boolean, langPairPromise: Promise<{sourceLanguage?: string, targetLanguage?: string}> }
| {
phase: "init-failure";
event: Event;
screenX: number;
screenY: number;
sourceText: string;
isTextSelected: boolean;
langPairPromise: Promise<{
sourceLanguage?: string;
targetLanguage?: string;
}>;
}
// The translation failed to complete.
| { phase: "translation-failure"; sourceLanguage: string; targetLanguage: string, sourceText: string, }
| {
phase: "translation-failure";
sourceLanguage: string;
targetLanguage: string;
sourceText: string;
}
// The selected language pair is determined to be translatable.
| { phase: "translatable"; sourceLanguage: string; targetLanguage: string, sourceText: string, }
| {
phase: "translatable";
sourceLanguage: string;
targetLanguage: string;
sourceText: string;
}
// The panel is actively translating the source text.
| { phase: "translating"; sourceLanguage: string; targetLanguage: string, sourceText: string, }
| {
phase: "translating";
sourceLanguage: string;
targetLanguage: string;
sourceText: string;
}
// The source text has been translated successfully.
| { phase: "translated"; sourceLanguage: string; targetLanguage: string, sourceText: string, translatedText: string, }
| {
phase: "translated";
sourceLanguage: string;
targetLanguage: string;
sourceText: string;
translatedText: string;
}
// The source language is not currently supported by Translations in Firefox.
| { phase: "unsupported"; detectedLanguage: string; targetLanguage: string, sourceText: string }
| {
phase: "unsupported";
detectedLanguage: string;
targetLanguage: string;
sourceText: string;
};
export type RequestTranslationsPort = (languagePair: LanguagePair) => Promise<MessagePort>
export type RequestTranslationsPort = (
languagePair: LanguagePair
) => Promise<MessagePort>;
export type TranslationsPortMessages = {
type: "TranslationsPort:TranslationRequest",
translationId: string,
sourceText: string,
isHTML: boolean,
}
type: "TranslationsPort:TranslationRequest";
translationId: string;
sourceText: string;
isHTML: boolean;
};
export type EngineStatus = "uninitialized" | "ready" | "error" | "closed";
export type PortToPage =
| { type: "TranslationsPort:TranslationResponse", targetText: string, translationId: number }
| { type: "TranslationsPort:GetEngineStatusResponse", status: EngineStatus }
| { type: "TranslationsPort:EngineTerminated" }
| {
type: "TranslationsPort:TranslationResponse";
targetText: string;
translationId: number;
}
| { type: "TranslationsPort:GetEngineStatusResponse"; status: EngineStatus }
| { type: "TranslationsPort:EngineTerminated" };

View File

@@ -4,31 +4,39 @@
declare global {
type DeclaredLazy<T> = {
[P in keyof T]:
T[P] extends (() => infer U) ? U :
T[P] extends keyof LazyModules ? Exports<T[P], P> :
T[P] extends { pref: string, default?: infer U } ? Widen<U> :
T[P] extends { service: string, iid?: infer U } ? nsQIResult<U> :
never;
}
[P in keyof T]: T[P] extends () => infer U
? U
: T[P] extends keyof LazyModules
? Exports<T[P], P>
: T[P] extends { pref: string; default?: infer U }
? Widen<U>
: T[P] extends { service: string; iid?: infer U }
? nsQIResult<U>
: never;
};
type LazyDefinition = Record<string,
string |
(() => any) |
{ service: string, iid: nsIID } |
{ pref: string, default?, onUpdate?, transform? }
type LazyDefinition = Record<
string,
| string
| (() => any)
| { service: string; iid: nsIID }
| { pref: string; default?; onUpdate?; transform? }
>;
}
type Exports<M, P> = M extends keyof LazyModules ? IfKey<LazyModules[M], P> : never;
type Exports<M, P> = M extends keyof LazyModules
? IfKey<LazyModules[M], P>
: never;
type IfKey<T, K> = K extends keyof T ? T[K] : never;
type LazyModules = import("./generated/lib.gecko.modules").LazyModules;
type Widen<T> =
T extends boolean ? boolean :
T extends number ? number :
T extends string ? string :
never;
type Widen<T> = T extends boolean
? boolean
: T extends number
? number
: T extends string
? string
: never;
export {};

View File

@@ -21,17 +21,27 @@ interface Document {
}
type nsIGleanPingNoReason = {
[K in keyof nsIGleanPing]: K extends "submit" ? (_?: never) => void : nsIGleanPing[K];
}
[K in keyof nsIGleanPing]: K extends "submit"
? (_?: never) => void
: nsIGleanPing[K];
};
type nsIGleanPingWithReason<T> = {
[K in keyof nsIGleanPing]: K extends "submit" ? (reason: T) => void : nsIGleanPing[K];
}
[K in keyof nsIGleanPing]: K extends "submit"
? (reason: T) => void
: nsIGleanPing[K];
};
interface MessageListenerManagerMixin {
// Overloads that define `data` arg as required, since it's ~always expected.
addMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })});
removeMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })});
addMessageListener(
msg: string,
listener: { receiveMessage(_: ReceiveMessageArgument & { data }) }
);
removeMessageListener(
msg: string,
listener: { receiveMessage(_: ReceiveMessageArgument & { data }) }
);
}
interface MozQueryInterface {
@@ -52,16 +62,20 @@ interface nsISupports {
}
interface nsIXPCComponents_Constructor {
<const T, IIDs = nsIXPCComponents_Interfaces>(cid, id: T, init?): {
<const T, IIDs = nsIXPCComponents_Interfaces>(
cid,
id: T,
init?
): {
new (...any): nsQIResult<T extends keyof IIDs ? IIDs[T] : T>;
(...any): nsQIResult<T extends keyof IIDs ? IIDs[T] : T>;
}
};
}
interface ComponentsExceptionOptions {
result?: number,
stack?: nsIStackFrame,
data?: object,
result?: number;
stack?: nsIStackFrame;
data?: object;
}
interface nsIException extends Exception {}
@@ -76,7 +90,7 @@ interface nsIXPCComponents_Exception {
}
interface nsIXPCComponents_ID {
(uuid: string): nsID
(uuid: string): nsID;
}
interface nsIXPCComponents_utils_Sandbox {
@@ -87,7 +101,7 @@ interface nsXPCComponents_Classes {
[cid: string]: {
createInstance<T>(aID: T): nsQIResult<T>;
getService<T>(aID?: T): unknown extends T ? nsISupports : nsQIResult<T>;
}
};
}
// Generic overloads.

View File

@@ -15,10 +15,12 @@ interface nsID<uuid = string> {
* and expose constants defined on the class, including variants from enums.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#45
*/
type nsJSIID<iface, enums = {}> = nsID & Constants<iface> & enums & {
new (_: never): void;
prototype: iface;
}
type nsJSIID<iface, enums = {}> = nsID &
Constants<iface> &
enums & {
new (_: never): void;
prototype: iface;
};
/** A union type of all known interface IIDs. */
type nsIID = nsIXPCComponents_Interfaces[keyof nsIXPCComponents_Interfaces];

View File

@@ -5,7 +5,7 @@ eslint:
include: ['.']
exclude: []
# When adding to this list, consider updating hooks_js_format.py as well.
extensions: ['mjs', 'js', 'json', 'jsx', 'html', 'sjs', 'xhtml']
extensions: ['mjs', 'js', 'json', 'jsx', 'html', 'sjs', 'xhtml', '.ts']
support-files:
- '**/.eslintrc.js'
- '.eslintrc*.js'

View File

@@ -28,6 +28,7 @@ file-perm:
- .rst
- .svg
- .toml
- .ts
- .ttf
- .wasm
- .webidl

View File

@@ -33,7 +33,7 @@ def run_js_format(hooktype, changedFiles):
# No files have been touched
return
extensions = (".js", ".jsx", ".json", ".mjs", "sjs", "html", "xhtml")
extensions = (".js", ".jsx", ".json", ".mjs", ".sjs", ".html", ".xhtml", ".ts")
path_list = []
for filename in sorted(changedFiles):
# Ignore files unsupported in eslint and prettier

View File

@@ -224,5 +224,6 @@ tools/@types/subs/
tools/browsertime/package.json
tools/browsertime/package-lock.json
tools/ts/error_list.json
tools/ts/test/baselines/
try_task_config.json
xpcom/idl-parser/xpidl/fixtures/xpctest.d.json