Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(treewide): Enable strict null checking #9975

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ prettier: browser/node_modules
prettier-write: browser/node_modules
@make -C browser prettier-write

betterer: browser/node_modules
@make -C browser betterer

betterer-write: browser/node_modules
@make -C browser betterer-write

install-exec-hook:
cd $(DESTDIR)$(bindir) && \
$(LN_S) coolconfig loolconfig && \
Expand Down Expand Up @@ -761,7 +767,7 @@ check-for-system-nss:

check-recursive: eslint

check: check-for-system-nss prettier eslint check-recursive
check: check-for-system-nss prettier eslint betterer check-recursive
$(GEN_COVERAGE_COMMAND)

coverage-report:
Expand Down
18 changes: 18 additions & 0 deletions browser/.betterer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { eslint: eslintBetter } = require('@betterer/eslint');
const globby = import('globby');
const { resolve } = require('path');

const eslintIgnorePath = resolve(__dirname, ".eslintignore");

const eslintTypescriptIncludes = async () => (await globby).globbySync(["**/*.ts"], { ignoreFiles: eslintIgnorePath });

module.exports = {
'avoid non-null assertions': async () =>
eslintBetter({
'@typescript-eslint/no-non-null-assertion': 'error',
}).include(await eslintTypescriptIncludes()),
'avoid expressions which have no effect': async () =>
eslintBetter({
'@typescript-eslint/no-unused-expressions': 'error',
}).include(await eslintTypescriptIncludes()),
};
1,491 changes: 1,491 additions & 0 deletions browser/.betterer.results

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion browser/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"@typescript-eslint/no-namespace": "off",
"no-inner-declarations": "off",
"no-constant-condition": "off",
"@typescript-eslint/triple-slash-reference": "off"
"@typescript-eslint/triple-slash-reference": "off",

"@typescript-eslint/no-non-null-assertion": "off", // improving in .betterer.ts
"@typescript-eslint/no-unused-expressions": "off" // improving in .betterer.ts
}
}
]
Expand Down
11 changes: 11 additions & 0 deletions browser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ define global_file
@$(NODE) node_modules/uglify-js/bin/uglifyjs $< --output $@)
endef

define run_betterer_check
node_modules/@betterer/cli/bin/betterer -c ./.betterer.js $(1)
endef

define run_eslint_check
@$(NODE) node_modules/eslint/bin/eslint.js \
--resolve-plugins-relative-to $(abs_builddir) \
Expand Down Expand Up @@ -703,6 +707,7 @@ $(INTERMEDIATE_DIR)/cool-src.js: tscompile.done $(call prereq_cool) $(COOL_JS_DS
@printf "Checking for obsolete JS build intermediates in this makefile... "
@if ! test "z$(COOL_ASSERT_INTERSECT)" == "z"; then echo; echo "Error: please remove obsolete files:"; echo "$(COOL_ASSERT_INTERSECT)"; exit 1; else echo "clean"; fi
@echo "Checking for cool JS errors..."
$(call run_betterer_check,ci) || echo "Betterer doesn't have the latest state of the project. To fix it, you can run 'make betterer-write'"
$(call run_eslint_check,$(srcdir)/src $(srcdir)/js)
$(call run_prettier_check,--debug-check $(srcdir)/src $(srcdir)/js/global.js)
@echo "Bundling cool..."
Expand Down Expand Up @@ -1152,6 +1157,12 @@ prettier-write:
$(srcdir)/js \
$(srcdir)/admin/src)

betterer:
$(call run_betterer_check,ci) || (echo "Betterer doesn't have the latest state of the project. To fix it, you can run 'make betterer-write'" && exit 1)

betterer-write:
$(call run_betterer_check,run)

MOCHA_TEST_LOG = "`pwd`/mocha.log"
DUPLICATION_TEST_LOG = "`pwd`/duplication.log"
check-local: $(MOCHA_TS_JS_FILES)
Expand Down
6 changes: 5 additions & 1 deletion browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.8.0-dev",
"description": "Collabora Online front-end",
"devDependencies": {
"@betterer/cli": "^5.4.0",
"@betterer/eslint": "^5.4.0",
"@braintree/sanitize-url": "6.0.2",
"@types/jquery": "^3.5.29",
"@types/jquery.contextmenu": "^1.7.38",
Expand Down Expand Up @@ -52,11 +54,13 @@
],
"license": "BSD-2-Clause",
"dependencies": {
"globby": "^14.0.2",
"jsdom": "^16.4.0"
},
"scripts": {
"test": "mocha 'mocha_tests/**/*.js'",
"test-single": "mocha",
"duplication": "jscpd ./src/ --exitCode 1 --min-lines 17"
"duplication": "jscpd ./src/ --exitCode 1 --min-lines 17",
"betterer": "betterer -c ./.betterer.js"
}
}
23 changes: 13 additions & 10 deletions browser/src/app/GraphicSelectionMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/

class GraphicSelection {
public static rectangle: cool.SimpleRectangle = null;
public static rectangle: cool.SimpleRectangle | null = null;
public static extraInfo: any = null;
public static selectionAngle: number = 0;
public static handlesSection: ShapeHandlesSection = null;
public static handlesSection: ShapeHandlesSection | null = null;

public static hasActiveSelection() {
return this.rectangle !== null;
Expand Down Expand Up @@ -43,8 +43,8 @@ class GraphicSelection {
var videoDesc = JSON.parse(textMsg);

if (this.hasActiveSelection()) {
videoDesc.width = this.rectangle.cWidth;
videoDesc.height = this.rectangle.cHeight;
videoDesc.width = this.rectangle!.cWidth;
videoDesc.height = this.rectangle!.cHeight;
}

// proxy cannot identify RouteToken if it is encoded
Expand Down Expand Up @@ -82,8 +82,8 @@ class GraphicSelection {
}

static renderDarkOverlay() {
var topLeft = new L.Point(this.rectangle.pX1, this.rectangle.pY1);
var bottomRight = new L.Point(this.rectangle.pX2, this.rectangle.pY2);
var topLeft = new L.Point(this.rectangle!.pX1, this.rectangle!.pY1);
var bottomRight = new L.Point(this.rectangle!.pX2, this.rectangle!.pY2);

if (app.map._docLayer.isCalcRTL()) {
// Dark overlays (like any other overlay) need regular document coordinates.
Expand Down Expand Up @@ -138,7 +138,7 @@ class GraphicSelection {
);

if (hasGridOffset)
this.rectangle.moveBy([
this.rectangle!.moveBy([
app.map._docLayer._shapeGridOffset.x,
app.map._docLayer._shapeGridOffset.y,
]);
Expand Down Expand Up @@ -177,10 +177,13 @@ class GraphicSelection {
app.sectionContainer.addSection(this.handlesSection);
}

this.handlesSection.setPosition(this.rectangle.pX1, this.rectangle.pY1);
this.handlesSection!.setPosition(
this.rectangle!.pX1,
this.rectangle!.pY1,
);
extraInfo.hasTableSelection = app.map._docLayer.hasTableSelection(); // scaleSouthAndEastOnly
this.handlesSection.refreshInfo(this.extraInfo);
this.handlesSection.setShowSection(true);
this.handlesSection!.refreshInfo(this.extraInfo);
this.handlesSection!.setShowSection(true);
app.sectionContainer.requestReDraw();
} else if (
this.handlesSection &&
Expand Down
Loading
Loading