Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Add strict null checking **DRAFT** #25

Draft
wants to merge 15 commits into
base: main-forked
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

[*.{json,md,yml}]
indent_style = space
indent_size = 2

[*.{ts,js}]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
22 changes: 0 additions & 22 deletions .github/workflows/lint.yml

This file was deleted.

105 changes: 63 additions & 42 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,83 @@
name: Static Checks

on: pull_request
name: Pull request

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run lint-check-only
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run test
- uses: actions/checkout@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run test
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run lint
- uses: actions/checkout@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run lint
docs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build:doc
- run: git diff-files --ignore-all-space --name-only --exit-code
- uses: actions/checkout@v2
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run build:doc
- run: git diff-files --ignore-all-space --name-only --exit-code
22 changes: 4 additions & 18 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
module.exports = {
printWidth: 80,
semi: false,
trailingComma: "all",
tabWidth: 4,
overrides: [
{
files: ["*.json"],
options: {
tabWidth: 2,
},
},
{
files: "*.md",
options: {
tabWidth: 2,
},
},
],
printWidth: 80,
semi: false,
trailingComma: "all",
editorConfig: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defer basic settings to .editorconfig

}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [next] - TBD

## [4.5.0] - TBD

### Changed

- Enable TypeScript strict null checks.
- Avoid fetching if caller doesn't provide Window dependency.

### Security

- Address security alery: [Inefficient Regular Expression Complexity in moment](https://github.com/cbsinteractive/openinsights/security/dependabot/21)

## [4.4.1] - 2022-07-21

### Security
Expand Down
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"build": "tsc --build",
"build:doc": "rimraf doc && typedoc src/index.ts",
"build:release": "rimraf dist && rollup -c",
"lint": "tsc && eslint --fix 'src/**'",
"lint-check-only": "tsc && eslint 'src/**'",
"lint": "tsc --noEmit --strictNullChecks && eslint --fix 'src/**'",
"lint-check-only": "tsc --noEmit --strictNullChecks && eslint 'src/**'",
"test": "jest --coverage",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
"prepublishOnly": "npm run build:release"
Expand Down
7 changes: 7 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ export enum KnownErrors {
*/
TestExecution,
}

export class WindowUndefinedError extends Error {
constructor(label: string) {
super(`Window undefined (${label})`)
Object.setPrototypeOf(this, new.target.prototype)
}
}
6 changes: 5 additions & 1 deletion src/lib/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BeaconHandler } from "../util/beaconHandler"
import { WindowUndefinedError } from "./errors"
import { asyncGetEntry } from "./resourceTiming"
import { Test } from "./test"

Expand All @@ -21,7 +22,7 @@ export interface FetchTestResultBundle {
}

export interface Dependencies {
window: Window & typeof globalThis
window: (Window & typeof globalThis) | undefined
}

/**
Expand Down Expand Up @@ -116,6 +117,9 @@ export abstract class Fetch<
*/
test(): Promise<void> {
const defaultTimeout = 5000
if (!this._deps.window) {
return this.onError(new WindowUndefinedError("Fetch.test"))
}
return Promise.all([
this.fetchObject(),
asyncGetEntry(
Expand Down