Skip to content

Commit

Permalink
🚨 apply eqeqeq lint rule (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhomer authored Dec 11, 2022
1 parent 638272f commit 0b01043
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
out/
output/

bundle.js

packages/site/public/garden.json
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"no-only-tests/no-only-tests": ["error", { "fix": true }],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"sonarjs/cognitive-complexity": "off"
"sonarjs/cognitive-complexity": "off",
"eqeqeq": ["error", "smart"]
},
"env": {
"node": true
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"clean:full": "pnpm clean && rimraf node_modules",
"dev": "pnpm --filter @garden/site dev",
"dev:test": "pnpm --filter @garden/site dev:test",
"eslint": "pnpm --filter {packages/**} eslint",
"eslint:fix": "pnpm --filter {packages/**} eslint:fix",
"eslint:packages": "pnpm --no-bail --filter {packages/**} eslint",
"eslint:config": "eslint --print-config .eslintrc.json",
"eslint:fix": "pnpm --no-bail --filter {packages/**} eslint:fix",
"export": "pnpm --filter @garden/site export",
"lint": "pnpm prettier && pnpm eslint",
"lint": "pnpm prettier && pnpm eslint:packages",
"lint:fix": "pnpm package:fix && pnpm prettier:fix && pnpm eslint:fix",
"package:fix": "format-package -w",
"prepare": "husky install",
Expand Down
2 changes: 1 addition & 1 deletion packages/end-to-end/src/test/features/steps/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Given, Then, When } from "@cucumber/cucumber";
import { expect } from "@playwright/test";

Given("I am on the {word} page", async function (name) {
await this.page.goto(`/${name == "index" ? "" : name}`);
await this.page.goto(`/${name === "index" ? "" : name}`);
});

When("I click {word}", async function (name) {
Expand Down
2 changes: 1 addition & 1 deletion packages/garden/src/file-garden-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class FileGardenRepository extends BaseGardenRepository {
});
// Files first
for (const child of directories) {
if (!child.isDirectory() && child.name.toLowerCase() == filename) {
if (!child.isDirectory() && child.name.toLowerCase() === filename) {
return resolve(explicitDirectory, child.name);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/garden/src/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ async function* findFilesInNamedDirectoryDeep(
for (const child of directories) {
const resolved = resolve(directory, child.name);
if (child.isDirectory() && shouldIncludeDirectory(config, child.name)) {
if (child.name == name) {
const children = await readdir(resolved, { withFileTypes: true });
const children = await readdir(resolved, { withFileTypes: true });
if (child.name === name) {
for (const candidate of children) {
if (candidate.isFile()) {
yield candidate.name;
Expand All @@ -54,7 +54,7 @@ export async function findAbsoluteFile(
const directories = await readdir(directory, { withFileTypes: true });
// Files first
for (const child of directories) {
if (!child.isDirectory() && child.name == filename) {
if (!child.isDirectory() && child.name === filename) {
return resolve(directory, child.name);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/garden/src/garden.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ describe("garden", () => {
expect(Object.keys(metaMap)).toHaveLength(3);
expect(
metaMap[myFilename].links
.filter((link) => link.type == LinkType.Child)
.filter((link) => link.type === LinkType.Child)
.map((link) => link.name)
).toEqual([sectionTitle]);
expect(metaMap["my-filename"].title).toBe("thing title");
expect(
metaMap["my-filename#section-title"].links
.filter((link) => link.type == LinkType.Child)
.filter((link) => link.type === LinkType.Child)
.map((link) => link.name)
).toEqual(["my-filename#sub-section-title"]);
expect(metaMap[sectionTitle].title).toBe("section title");
Expand Down
20 changes: 11 additions & 9 deletions packages/garden/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const loadThingIntoMetaMap = async (metaMap: MetaMap, thing: Thing) => {

thingMeta.forEach((singleThingMeta) => {
const singleThingName =
singleThingMeta.type == ThingType.Child
singleThingMeta.type === ThingType.Child
? thingName + "#" + linkResolver(singleThingMeta.title)
: thingName;
metaMap[singleThingName] = {
Expand Down Expand Up @@ -196,7 +196,7 @@ const generateMeta = async (
type: link.type,
value: link.value,
};
if (thing.value == 0 || metaMap[link.name]?.value == 0) {
if (thing.value === 0 || metaMap[link.name]?.value === 0) {
transformedLink.value = 0;
}
return transformedLink;
Expand All @@ -218,11 +218,11 @@ const reduceAliases = (meta: { [key: string]: Meta }) => {
const reducibleAliases: [string, string[]][] = Object.entries(meta)
.filter(
([, value]) =>
value.type == ThingType.NaturallyWanted &&
value.type === ThingType.NaturallyWanted &&
value.links.length > 0 &&
value.links.every(
(link) =>
link.type == LinkType.NaturalAlias &&
link.type === LinkType.NaturalAlias &&
(link.name in meta ||
naturallyWantedAliases.indexOf(link.name) > -1)
)
Expand All @@ -236,7 +236,7 @@ const reduceAliases = (meta: { [key: string]: Meta }) => {
const reducibleAliasNames = reducibleAliases.map(([key]) => key);
return Object.fromEntries(
Object.entries(meta)
.filter(([key]) => reducibleAliasNames.indexOf(key) == -1)
.filter(([key]) => reducibleAliasNames.indexOf(key) === -1)
.map(([key, { title, type, aliases, links, value }]) => [
key,
{
Expand Down Expand Up @@ -292,7 +292,7 @@ export const findUnwantedLinks = (meta: MetaMap) => {
if (!thing) {
return false;
}
return thing.type == ThingType.Item || thing.type === ThingType.Wanted;
return thing.type === ThingType.Item || thing.type === ThingType.Wanted;
});
})
.map((entry) => entry[0]);
Expand All @@ -302,7 +302,7 @@ export const findUnwantedLinks = (meta: MetaMap) => {
return meta[key].links
.filter(
(link) =>
link.type == LinkType.To && !explicitThingNames.includes(link.name)
link.type === LinkType.To && !explicitThingNames.includes(link.name)
)
.map((link) => link.name);
})
Expand Down Expand Up @@ -391,7 +391,9 @@ const findBackLinks = (things: Things, name: string) => {
export const findKnownThings = (things: Things) => {
return Object.keys(
Object.fromEntries(
Object.entries(things).filter(([, thing]) => thing.type == ThingType.Item)
Object.entries(things).filter(
([, thing]) => thing.type === ThingType.Item
)
)
);
};
Expand Down Expand Up @@ -422,7 +424,7 @@ export const toConfig = (options: GardenOptions): GardenConfig => ({
});

const toRepository = (config: GardenConfig): GardenRepository => {
if (config.type == "file") {
if (config.type === "file") {
return new FileGardenRepository(
config.directory,
config.excludedDirectories
Expand Down
7 changes: 4 additions & 3 deletions packages/garden/src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
} from "./content";
import { Garden } from "./garden";

export const justExplicitLinks = (link: Link) => link.type == LinkType.To;
export const justNaturalLinks = (link: Link) => link.type == LinkType.NaturalTo;
export const justExplicitLinks = (link: Link) => link.type === LinkType.To;
export const justNaturalLinks = (link: Link) =>
link.type === LinkType.NaturalTo;
export const justNaturalAliasLinks = (link: Link) =>
link.type == LinkType.NaturalAlias;
link.type === LinkType.NaturalAlias;
export const toLinkName = (link: Link) => link.name;

export const findLinks = async (garden: Garden, item: Item) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/garden/src/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { gardenConfig } from "./test-helpers";
const garden = createGarden(gardenConfig);

const toName = (link: Link) => link.name;
const justNaturalLinks = (link: Link) => link.type == LinkType.NaturalTo;
const justNaturalLinks = (link: Link) => link.type === LinkType.NaturalTo;

describe("markdown", () => {
describe("basic content", () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/garden/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function toSections(root: Parent) {
}
}
}
const section = depth == 1 ? sections[0] : sections[sectionCount - 1];
const section = depth === 1 ? sections[0] : sections[sectionCount - 1];
if (!skip) {
section.children.push(node);
}
Expand Down Expand Up @@ -114,15 +114,17 @@ function getFirstValue(node: Node, filter: (node: Node) => boolean): string {
}

function getFrontText(node: Section, filter: (node: Node) => boolean) {
const firstParagraph = node.children.find((node) => node.type == "paragraph");
const firstParagraph = node.children.find(
(node) => node.type === "paragraph"
);
if (firstParagraph) {
return getFirstValue(firstParagraph, filter);
}
return null;
}

function extractTitle(node: Section) {
const firstHeading = node.children.find((node) => node.type == "heading");
const firstHeading = node.children.find((node) => node.type === "heading");
if (!firstHeading) {
return getFrontText(node, justTextNodes) ?? "no title";
}
Expand Down
2 changes: 1 addition & 1 deletion packages/garden/src/nlp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function naturalProcess(
.map((term: Term) => {
const rawRoot = strip(term.noun.root);
const root = rawRoot.replace(postStrip, "");
if (term.noun.adjectives.length == 0) {
if (term.noun.adjectives.length === 0) {
return root;
}
return [
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/src/collide-rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function yCenterOfBox(d: GraphNode, box: number[]) {
// box is [x,y,width,height]
function apply(d: GraphNode, box: number[], strength: number) {
return (quad: QuadtreeInternalNode<GraphNode> | QuadtreeLeaf<GraphNode>) => {
if (quad.length == 4 || !d) {
if (quad.length === 4 || !d) {
return;
}
if ((quad.data.index ?? 0) <= (d.index ?? 0)) {
Expand Down
20 changes: 13 additions & 7 deletions packages/graph/src/default-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ const linkTypeForceWeight = (linkType: LinkType) => {
};

const linkDepthForceWeight = (link: NodeLink) =>
link.depth == 0 ? 1.0 : link.depth == 1 ? 1.0 : link.depth == 2 ? 0.15 : 0.08;
link.depth === 0
? 1.0
: link.depth === 1
? 1.0
: link.depth === 2
? 0.15
: 0.08;

type DefaultConfigurationParameters = {
viewWidth: number;
Expand Down Expand Up @@ -64,11 +70,11 @@ const defaultConfiguration = (
depth,
getRadius: (d: Node | SimulationNodeDatum) => {
if ("depth" in d) {
return d.depth == 0
return d.depth === 0
? DEPTH_1_RADIUS
: d.depth == 1
: d.depth === 1
? 15
: d.depth == 2
: d.depth === 2
? 5
: 2;
} else {
Expand All @@ -79,11 +85,11 @@ const defaultConfiguration = (
// How much node repels
getCharge: (factor: number) => (d: Node | SimulationNodeDatum) => {
if ("depth" in d) {
return d.depth == 0
return d.depth === 0
? -1000 * factor
: d.depth == 1
: d.depth === 1
? -2000 * factor
: d.depth == 2
: d.depth === 2
? -50 * factor
: -5 * factor;
} else {
Expand Down
18 changes: 9 additions & 9 deletions packages/graph/src/find-deep-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const backLinks = (
name: string,
depth: number,
predicate = (link: Link) =>
link.type == LinkType.To ||
link.type == LinkType.NaturalAlias ||
link.type == LinkType.Child,
link.type === LinkType.To ||
link.type === LinkType.NaturalAlias ||
link.type === LinkType.Child,
backLinkType = LinkType.From
): ItemLink[] => {
const backLinksAvailable = backLinkCache[name];
Expand Down Expand Up @@ -47,7 +47,7 @@ const goDeeper = (
return true;
} else if (depth > HARD_DEPTH) {
return false;
} else if (linkType == LinkType.Child) {
} else if (linkType === LinkType.Child) {
// Show the link to child as long as we haven't gone past the hard depth
return true;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ const findDeepLinks = (
things,
name,
depth,
(link: Link) => link.type == LinkType.NaturalTo,
(link: Link) => link.type === LinkType.NaturalTo,
LinkType.NaturalFrom
),
];
Expand All @@ -120,10 +120,10 @@ const findDeepLinks = (
index ===
self.findIndex(
(compareTo) =>
((value.source == compareTo.source &&
value.target == compareTo.target) ||
(value.source == compareTo.target &&
value.target == compareTo.source)) &&
((value.source === compareTo.source &&
value.target === compareTo.target) ||
(value.source === compareTo.target &&
value.target === compareTo.source)) &&
// choose one with lowest depth
value.depth >= compareTo.depth
)
Expand Down
6 changes: 3 additions & 3 deletions packages/graph/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ItemLink, Things } from "@garden/types";
import { Graph, InitialNodeValueMap, NodeType } from "./types";

const countSiblings = (name: string, links: Array<ItemLink>, depth: number) => {
if (depth == 0) {
if (depth === 0) {
return 1;
}
const linksToName = links.filter((link) => link.target === name);
const parentLink = linksToName.find((link) => link.depth == depth);
const parentLink = linksToName.find((link) => link.depth === depth);
if (!parentLink) {
throw `Cannot find parent of ${name} from ${JSON.stringify(
linksToName
Expand Down Expand Up @@ -43,7 +43,7 @@ export const createGraph = (
const connections = links
.filter((link) => link.target === name)
.map((link) => link.depth);
if (connections.length == 0) {
if (connections.length === 0) {
return 0;
} else return Math.min(...connections);
};
Expand Down
10 changes: 5 additions & 5 deletions packages/graph/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const update = (
(d: GraphNode) =>
config.yOffsetText -
((depth) =>
depth == 0 ? 40 : depth == 1 ? 30 : depth == 2 ? 15 : 10)(
depth === 0 ? 40 : depth === 1 ? 30 : depth === 2 ? 15 : 10)(
d.depth
)
)
Expand All @@ -173,10 +173,10 @@ const update = (
(update) => {
update
.classed("hideLabel", (d: GraphNode) => !d.showLabel)
.classed("depth-0", (d: GraphNode) => d.depth == 0)
.classed("depth-1", (d: GraphNode) => d.depth == 1)
.classed("depth-2", (d: GraphNode) => d.depth == 2)
.classed("depth-3", (d: GraphNode) => d.depth == 3)
.classed("depth-0", (d: GraphNode) => d.depth === 0)
.classed("depth-1", (d: GraphNode) => d.depth === 1)
.classed("depth-2", (d: GraphNode) => d.depth === 2)
.classed("depth-3", (d: GraphNode) => d.depth === 3)
.classed("fixed", (d: GraphNode) => d.fx !== undefined)
.select("circle")
.attr("r", config.getRadius);
Expand Down
4 changes: 2 additions & 2 deletions packages/site/src/pages/x/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export async function getStaticProps() {
(name) =>
listOfThings.filter((thing) =>
thing.links.find((link) => link.name === name)
).length == 1
).length === 1
);
const singleNaturalWantedThings = wantedThings.filter(
(name) =>
listOfThings.filter((thing) =>
thing.links.find(
(link) => link.name === name && link.type === LinkType.NaturalTo
)
).length == 1
).length === 1
);

return {
Expand Down
Loading

1 comment on commit 0b01043

@vercel
Copy link

@vercel vercel bot commented on 0b01043 Dec 11, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.