Skip to content

Commit

Permalink
Typescript Conversion (#202)
Browse files Browse the repository at this point in the history
- Convert all of wabac.js to typescript!
- wombat built as separate phase, then bundled in second phase.
- types added where possible, including for IDB
- added @ts-expect-error comments / todos added for further type work
- deps: bump warcio to 2.3.1
- add two exports: default export for rewriting / multiwacz loading, swlib export for extending service worker functionality

---------
Co-authored-by: Ilya Kreymer <[email protected]>
  • Loading branch information
emma-sg authored Oct 17, 2024
1 parent a493601 commit 1c3acfc
Show file tree
Hide file tree
Showing 118 changed files with 21,453 additions and 10,501 deletions.
142 changes: 109 additions & 33 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,112 @@
/* eslint-env node */
/** @type {import('eslint').Linter.Config} */
module.exports = {
"env": {
"browser": true,
"es6": true
parser: "@typescript-eslint/parser",
env: {
browser: true,
commonjs: true,
es2017: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"prettier",
],
plugins: ["@typescript-eslint"],
parserOptions: {
project: ["./tsconfig.eslint.json"],
tsconfigRootDir: __dirname,
},
root: true,
rules: {
/* start stylistic rules */
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/prefer-readonly": "warn",
"@typescript-eslint/class-literal-property-style": ["warn", "getters"],
"@typescript-eslint/consistent-generic-constructors": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/non-nullable-type-assertion-style": "warn",
"@typescript-eslint/prefer-for-of": "warn",
// "@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/no-meaningless-void-operator": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "warn",
"@typescript-eslint/no-unnecessary-type-arguments": "warn",
"@typescript-eslint/prefer-reduce-type-parameter": "warn",
"@typescript-eslint/promise-function-async": "warn",
/* end stylistic rules */

/* start recommended rules */
"no-restricted-globals": [2, "event", "error"],
"@typescript-eslint/no-base-to-string": "warn",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/no-duplicate-type-constituents": "warn",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"no-implied-eval": "off",
"@typescript-eslint/no-implied-eval": "error",
"no-loss-of-precision": "off",
"@typescript-eslint/no-loss-of-precision": "warn",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{ checksVoidReturn: false },
],
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-redundant-type-constituents": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
/* TODO eventually turn all these on */
"@typescript-eslint/no-unsafe-argument": "warn",
// "@typescript-eslint/no-unsafe-assignment": "warn",
// "@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "warn",
// "@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/prefer-as-const": "warn",
"require-await": "off",
// "@typescript-eslint/require-await": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/method-signature-style": "error",
},
reportUnusedDisableDirectives: true,
ignorePatterns: ["__generated__", "__mocks__", "dist", "static"],
overrides: [
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: ["webpack.*.js", ".*.cjs"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"globals": {
"globalThis": false, //not writable
},
"rules": {
"no-restricted-globals": [
2,
"event", "window"
],
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
],
};
10 changes: 7 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- name: install
run: yarn install
Expand All @@ -21,4 +22,7 @@ jobs:
run: yarn test

- name: lint
run: yarn lint
run: yarn lint:check

- name: format
run: yarn format:check
6 changes: 3 additions & 3 deletions .github/workflows/npm-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
cache: 'yarn'
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
cache: "yarn"

- name: Yarn Install
run: yarn install --frozen-lockfile
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
**/*.wacz
**/adblock.gz
**/node_modules
**/dist
.tsimp
coverage
dist-wombat
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static/wombat*.js
Loading

0 comments on commit 1c3acfc

Please sign in to comment.