Skip to content

Commit

Permalink
Enforce usage of type-safe equality operators
Browse files Browse the repository at this point in the history
Using == / != is a source of bugs.

Rule doc page: https://eslint.org/docs/latest/rules/eqeqeq
  • Loading branch information
victorlin committed Nov 14, 2024
1 parent b4724ba commit 1bbf263
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ignorePatterns:

rules:
# Code quality rules
eqeqeq: error
no-unused-vars: error
no-use-before-define: ["error", { "functions": false, "classes": false }]
prefer-const: ["error", {"destructuring": "all"}]
Expand Down
4 changes: 2 additions & 2 deletions src/authz/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import tags from './tags.js';
*/
function authorized(user, action, object) {
// user may be null
assert(!user || user.authzRoles != null, "user.authzRoles is not null if user is not null");
assert(!user || user.authzRoles !== null, "user.authzRoles is not null if user is not null");
assert(actions.has(action), "action is known");
assert(object != null, "object is not null");
assert(object !== null, "object is not null");

/* As a safe guard, anonymous users can only ever read, regardless of
* policies right now. We don't have any use cases right now where letting
Expand Down
2 changes: 1 addition & 1 deletion src/sources/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class GroupSource extends Source {
let {title, byline, website, showDatasets, showNarratives} = frontMatter;

// Must be an allowed protocol
if (website != null) {
if (website !== null) {
const {protocol} = parseUrl(website) ?? {};
const allowedProtocols = new Set(["https:", "http:", "ftp:", "ftps:", "mailto:"]);
if (!allowedProtocols.has(protocol)) {
Expand Down
2 changes: 1 addition & 1 deletion src/upstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function copyHeaders(headerSource, headerNames) {
return Object.fromEntries(
headerNames
.map(name => [name, headerSource.get(name)])
.filter(([name, value]) => value != null && value !== "") // eslint-disable-line no-unused-vars
.filter(([name, value]) => value !== null && value !== "") // eslint-disable-line no-unused-vars
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const parseNarrativeLanguage = (narrative) => {
const normalizeHeaders = (headers) => {
const withValues =
Object.entries(headers)
.filter(([, value]) => value != null && value !== "");
.filter(([, value]) => value !== null && value !== "");

/* Use the WHATWG Headers object to do most of the normalization, including
* lowercasing and combining duplicate headers as appropriate.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function run(argv) {
proc.stderr.on("data", data => console.error(data.toString().replace(/\n$/, "")));

proc.on("close", (code, signal) => {
const result = code !== 0 || signal != null
const result = code !== 0 || signal !== null
? reject
: resolve;
return result({code, signal, argv});
Expand Down
2 changes: 1 addition & 1 deletion static-site/src/components/ExpandableTiles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ExpandableTiles = <AnyTile extends Tile>({tiles, tileWidth, tileHei
function tilesContainerRef(tilesContainer: HTMLDivElement) {
if (!tilesContainer) return;

if(tilesContainerHeight != tilesContainer.clientHeight) {
if(tilesContainerHeight !== tilesContainer.clientHeight) {
setTilesContainerHeight(tilesContainer.clientHeight)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const IndividualResource = ({resource, isMobile}: IndividualResourceProps
// don't do anything if the ref is undefined or the parent is not a div (IndividualResourceContainer)
if (!ref.current
|| !ref.current.parentNode
|| ref.current.parentNode.nodeName != 'DIV') return;
|| ref.current.parentNode.nodeName !== 'DIV') return;

/* The column CSS is great but doesn't allow us to know if an element is at
the top of its column, so we resort to JS */
Expand Down
2 changes: 1 addition & 1 deletion static-site/src/components/nav-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const NavBar = ({ minified }: {

return (
<NavContainer>
{Router.pathname != "/" && <>
{Router.pathname !== "/" && <>
<Logo />
<LogoType />
</>}
Expand Down

0 comments on commit 1bbf263

Please sign in to comment.