Skip to content

Commit

Permalink
Make enums const
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Jan 11, 2024
1 parent 0c7fa49 commit d8090cc
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 42 deletions.
7 changes: 5 additions & 2 deletions experiments/jsdns.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ this.jsdns = class extends ExtensionCommon.ExtensionAPI {
* @returns {{jsdns: browser.jsdns}}
*/
getAPI(context) {
const RCODE = {
/** @enum {number} */
// eslint-disable-next-line no-extra-parens
const RCODE = /** @type {const} */ ({
NoError: 0, // No Error [RFC1035]
FormErr: 1, // Format Error [RFC1035]
ServFail: 2, // Server Failure [RFC1035]
NXDomain: 3, // Non-Existent Domain [RFC1035]
NotImp: 4, // Non-Existent Domain [RFC1035]
Refused: 5, // Query Refused [RFC1035]
};
});
/** @type {{JSDNS: {configureDNS: typeof configureDNS, queryDNS: typeof queryDNS}}} */
const { JSDNS } = ChromeUtils.import("chrome://dkim_verifier_jsdns/content/JSDNS.jsm.js");
this.extension.callOnClose(this);
Expand All @@ -63,6 +65,7 @@ this.jsdns = class extends ExtensionCommon.ExtensionAPI {
async txt(name) {
const res = await JSDNS.queryDNS(name, "TXT");

/** @type {number} */
let resRcode = RCODE.NoError;
if (res.rcode !== undefined) {
resRcode = res.rcode;
Expand Down
8 changes: 6 additions & 2 deletions experiments/libunbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ class LibunboundWorker {
}
}
}
LibunboundWorker.Constants = {
/**
* @enum {number}
*/
// eslint-disable-next-line no-extra-parens
LibunboundWorker.Constants = /** @type {const} */ ({
RR_TYPE_A: 1,
RR_TYPE_A6: 38,
RR_TYPE_AAAA: 28,
Expand Down Expand Up @@ -346,7 +350,7 @@ LibunboundWorker.Constants = {
RR_TYPE_UNSPEC: 103,
RR_TYPE_WKS: 11,
RR_TYPE_X25: 19,
};
});


this.libunbound = class extends ExtensionCommon.ExtensionAPI {
Expand Down
8 changes: 6 additions & 2 deletions experiments/libunboundWorker.jsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ const postLog = {
},
};

const Constants = {
/**
* @enum {number}
*/
// eslint-disable-next-line no-extra-parens
const Constants = /** @type {const} */ ({
RR_TYPE_A: 1,
RR_TYPE_A6: 38,
RR_TYPE_AAAA: 28,
Expand Down Expand Up @@ -123,7 +127,7 @@ const Constants = {
RR_TYPE_UNSPEC: 103,
RR_TYPE_WKS: 11,
RR_TYPE_X25: 19,
};
});

/** @type {ctypes.Library?} */
let lib;
Expand Down
5 changes: 3 additions & 2 deletions modules/authVerifier.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ export default class AuthVerifier {
}

static get DKIM_RES() {
return {
// eslint-disable-next-line no-extra-parens
return /** @type {const} */ ({
SUCCESS: 10,
TEMPFAIL: 20,
PERMFAIL: 30,
PERMFAIL_NOSIG: 35,
NOSIG: 40,
};
});
}

/**
Expand Down
21 changes: 14 additions & 7 deletions modules/dkim/signRules.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ const log = Logging.getLogger("SignRules");
* rule types
*
* @public
* @enum {number}
*/
const RULE_TYPE = {
// eslint-disable-next-line no-extra-parens
const RULE_TYPE = /** @type {const} */ ({
ALL: 1, // all e-mails must be signed
NEUTRAL: 2,
HIDEFAIL: 3, // treat invalid signatures as nosig
};
});

/**
* default rule priorities
*
* @public
* @enum {number}
*/
const PRIORITY = {
// eslint-disable-next-line no-extra-parens
const PRIORITY = /** @type {const} */ ({
AUTOINSERT_RULE_ALL: 1100,
DEFAULT_RULE_ALL0: 2000, // used for e-mail providers
USERINSERT_RULE_HIDEFAIL: 2050,
Expand All @@ -58,13 +62,15 @@ const PRIORITY = {
DEFAULT_RULE_NEUTRAL: 2200,
USERINSERT_RULE_ALL: 3100,
USERINSERT_RULE_NEUTRAL: 3200,
};
});

const AUTO_ADD_RULE_FOR = {
/** @enum {number} */
// eslint-disable-next-line no-extra-parens
const AUTO_ADD_RULE_FOR = /** @type {const} */ ({
FROM_ADDRESS: 0,
SUB_DOMAIN: 1,
BASE_DOMAIN: 2,
};
});

/**
* Exported DKIM user signing rule.
Expand Down Expand Up @@ -507,7 +513,8 @@ export default class SignRules {
ruleDomain = await browser.mailUtils.getBaseDomainFromAddr(addr);
}

if (!Object.values(RULE_TYPE).includes(type)) {
// eslint-disable-next-line no-extra-parens
if (!Object.values(/** @type {{[key: string]: number}} */(RULE_TYPE)).includes(type)) {
throw new Error(`unknown rule type ${type}`);
}

Expand Down
23 changes: 0 additions & 23 deletions modules/dkim/signRulesProxy.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@
/* eslint-env webextensions */

export default class SignRulesProxy {
/** @readonly */
static get TYPE() {
return {
ALL: 1, // all e-mails must be signed
NEUTRAL: 2,
HIDEFAIL: 3, // treat invalid signatures as nosig
};
}

/** @readonly */
static get PRIORITY() {
return {
AUTOINSERT_RULE_ALL: 1100,
DEFAULT_RULE_ALL0: 2000, // used for e-mail providers
USERINSERT_RULE_HIDEFAIL: 2050,
DEFAULT_RULE_ALL: 2100,
DEFAULT_RULE_ALL_2: 2110, // used for different SDID for subdomains
DEFAULT_RULE_NEUTRAL: 2200,
USERINSERT_RULE_ALL: 3100,
USERINSERT_RULE_NEUTRAL: 3200,
};
}

/**
* @returns {Promise<import("./signRules.mjs.js").DkimSignRuleDefault[]>}
*/
Expand Down
5 changes: 3 additions & 2 deletions modules/dns.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ function checkOnlineStatus() {

export default class DNS {
static get RCODE() {
return {
// eslint-disable-next-line no-extra-parens
return /** @type {const} */ ({
NoError: 0, // No Error [RFC1035]
FormErr: 1, // Format Error [RFC1035]
ServFail: 2, // Server Failure [RFC1035]
NXDomain: 3, // Non-Existent Domain [RFC1035]
NotImp: 4, // Non-Existent Domain [RFC1035]
Refused: 5, // Query Refused [RFC1035]
};
});
}

/**
Expand Down
6 changes: 4 additions & 2 deletions modules/logging.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class Logger {

export default class Logging {
static get Level() {
return {
// eslint-disable-next-line no-extra-parens
return /** @type {const} */ ({
Fatal: 70,
Error: 60,
Warn: 50,
Expand All @@ -87,7 +88,7 @@ export default class Logging {
Debug: 20,
Trace: 10,
All: -1,
};
});
}

/**
Expand Down Expand Up @@ -157,6 +158,7 @@ export default class Logging {
});
}

/** @type {number} */
static #logLevel = Logging.Level.Debug;
/**
* @type {Logger[]}
Expand Down

0 comments on commit d8090cc

Please sign in to comment.