Require using const for variables that are never modified

And disallow modifying variables that are declared using `const`.

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-08-30 12:09:27 +02:00
committed by Alexis Sellier
parent 7c07baf35b
commit 853ed5c053
18 changed files with 39 additions and 34 deletions
+7 -2
View File
@@ -100,8 +100,13 @@
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
// Require using arrow functions as callbacks.
// https://eslint.org/docs/rules/prefer-arrow-callback
"prefer-arrow-callback": "error"
"prefer-arrow-callback": "error",
// Require using const for variables that are never modified after declared.
// https://eslint.org/docs/rules/prefer-const
"prefer-const": "error",
// Disallow modifying variables that are declared using const.
// https://eslint.org/docs/rules/no-const-assign
"no-const-assign": "error"
},
"settings": {
"svelte3/typescript": true
+1 -1
View File
@@ -35,7 +35,7 @@
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter') {
let elems = document.querySelectorAll<HTMLElement>('button.primary');
const elems = document.querySelectorAll<HTMLElement>('button.primary');
if (elems.length == 1) { // We only allow this when there's one primary button.
elems[0].click();
}
+8 -8
View File
@@ -11,7 +11,7 @@
let path = "";
let areaPath = "";
let heightWithPadding = viewBoxHeight + 16;
const heightWithPadding = viewBoxHeight + 16;
// The latest point on the x axis, starting at 0 until `viewBoxWidth`
let lastWidthPoint = viewBoxWidth;
@@ -20,10 +20,10 @@
const widthIteration = viewBoxWidth / 52;
// The highest value on the y axis
let commitCountArray: number[] = [];
const commitCountArray: number[] = [];
// The minimal amplitude shown e.g. commitCount = 1 => `minimalHeight` points of height in the SVG.
let minimalHeight = 5;
const minimalHeight = 5;
let week = 0;
@@ -41,11 +41,11 @@
if (commitCountArray.length < 52) commitCountArray.push(...new Array(52 - commitCountArray.length).fill(0));
let maxValue = Math.max(...commitCountArray);
let minValue = Math.min(...commitCountArray);
const maxValue = Math.max(...commitCountArray);
const minValue = Math.min(...commitCountArray);
// Normalizes the values to the viewBox dimensions
let normalizedArray =
const normalizedArray =
commitCountArray.map(c => {
// If we are not crossing the `viewBoxHeight` we want to return the actual value,
// and don't want to normalize <`minimalHeight` commit counts as huge spikes.
@@ -56,10 +56,10 @@
else { return c === 0 ? 0 : (viewBoxHeight - 0) * (c - minValue) / (maxValue - minValue); }
});
let path = normalizedArray
const path = normalizedArray
.slice(1)
.reduce((acc, curr) => {
let s = `${viewBoxWidth - widthIteration * i},${viewBoxHeight - curr}`;
const s = `${viewBoxWidth - widthIteration * i},${viewBoxHeight - curr}`;
lastWidthPoint = viewBoxWidth - widthIteration * i;
i += 1;
return acc.concat(s);
+1 -1
View File
@@ -14,7 +14,7 @@
export let subtle = false;
export let action = floating ? "Close" : "Back";
let body = message || (error && error.message) || "";
const body = message || (error && error.message) || "";
</script>
<Modal on:close error {floating} {subtle}>
+3 -3
View File
@@ -28,9 +28,9 @@
onMount(() => {
// Don't underline <a> tags that contain images.
let elems = container.querySelectorAll("a");
const elems = container.querySelectorAll("a");
for (let e of elems) {
for (const e of elems) {
if (e.firstElementChild instanceof HTMLImageElement) {
e.classList.add("no-underline");
}
@@ -39,7 +39,7 @@
// Iterate over all images, and fetch their data from the API, then
// replace the source with a Data-URL. We do this due to the absence
// of a static file server.
for (let i of container.querySelectorAll("img")) {
for (const i of container.querySelectorAll("img")) {
const path = i.getAttribute("src");
// Make sure the source isn't a URL before trying to fetch it from the repo
+1 -1
View File
@@ -4,7 +4,7 @@
import Icon from "@app/Icon.svelte";
import config from "@app/config.json";
let showReactions = false;
const showReactions = false;
const dispatch = createEventDispatcher();
</script>
+2 -2
View File
@@ -12,8 +12,8 @@
// When a user signs into a new seed we want to update the seed listing
$: formatSeeds = async () => {
return await Promise.all(Object.values(seeds).map(async session => {
let seed = await Seed.lookup(session.domain, config);
let key = `${seed.emoji} ${seed.host}`;
const seed = await Seed.lookup(session.domain, config);
const key = `${seed.emoji} ${seed.host}`;
return { key, value: seed.host, title: `Go to ${seed.host}`, badge: null };
}));
+3 -3
View File
@@ -31,11 +31,11 @@
if (! $session) { return [false]; }
if (!amount || amount === "0") { return [false, "Not able to withdraw zero tokens"]; }
if (toWei(amount).gt(maxWithdrawAmount)) return [false, `Reduce amount, max withdrawal is ${formatEther(maxWithdrawAmount)}`];
let currentTime = new Date().getTime();
let timelock = await calculateTimeLock(amount, $session.signer, config);
const currentTime = new Date().getTime();
const timelock = await calculateTimeLock(amount, $session.signer, config);
// Converting a 10 digit to 13 digit timestamp by multiplying by 1000
// since JS doesn't display a correct Date string when passing a 10 digit timestamp.
let nextAvailableWithdraw = lastWithdrawal.add(timelock).mul(1000);
const nextAvailableWithdraw = lastWithdrawal.add(timelock).mul(1000);
if (nextAvailableWithdraw.gt(currentTime)) return [false, `Not ready to withdraw, return after ${new Date(nextAvailableWithdraw.toNumber()).toLocaleString('en-GB')}`];
return [true];
+1 -1
View File
@@ -12,7 +12,7 @@
export let config: Config;
let error: Error;
let amount: string = window.history.state.amount;
const amount: string = window.history.state.amount;
let state: State = {
status: Status.Failed,
error: "Error withdrawing, something happened.",
+2 -2
View File
@@ -54,13 +54,13 @@
state = State.Signing;
try {
let tx = governance === Governance.Quorum
const tx = governance === Governance.Quorum
? await Org.createMultiSig([owner], 1, config)
: await Org.create(owner, config);
state = State.Pending;
let receipt = await tx.wait();
const receipt = await tx.wait();
org = Org.fromReceipt(receipt);
state = State.Success;
} catch (e: any) {
+1 -1
View File
@@ -59,7 +59,7 @@
state = State.Proposed;
} else {
state = State.Signing;
let tx = await org.setOwner(newOwner, config);
const tx = await org.setOwner(newOwner, config);
state = State.Pending;
await tx.wait();
state = State.Success;
+1 -1
View File
@@ -14,7 +14,7 @@
export let browserStore: Writable<Browser>;
export let noAnchor = false;
let { urn, peers, branches, seed, anchors } = project;
const { urn, peers, branches, seed, anchors } = project;
$: browser = $browserStore;
$: revision = browser.revision || commit;
+1 -1
View File
@@ -22,7 +22,7 @@
meta = peers.find(p => p.id === peer);
items = peers.map(p => {
if (! p.person?.name) console.debug("Not able to resolve peer identity for: ", p.id);
let key = p.person?.name ? `<strong>${p.person.name}</strong> ${p.id}` : p.id;
const key = p.person?.name ? `<strong>${p.person.name}</strong> ${p.id}` : p.id;
return { key, value: p.id, title: createTitle(p), badge: p.delegate ? "delegate" : null };
});
+1 -1
View File
@@ -27,7 +27,7 @@
export let content: proj.ProjectContent;
export let revision: string | null;
let parentName = project.profile ? formatProfile(project.profile.nameOrAddress, config) : null;
const parentName = project.profile ? formatProfile(project.profile.nameOrAddress, config) : null;
let pageTitle = parentName ? `${parentName}/${project.name}` : project.name;
const baseName = parentName
@@ -7,7 +7,7 @@
export let stats: DiffStats;
const diffDescription = ({ modified, created, deleted }: Diff): string => {
let s = [];
const s = [];
if (modified.length) {
s.push(`${modified.length} file(s) changed`);
+1 -1
View File
@@ -18,7 +18,7 @@
export let session: Session;
let error: Error | null = null;
let registrationOwner = owner || session.address;
const registrationOwner = owner || session.address;
const view = () => navigate(`/registrations/${name}.radicle.eth`, { state: { retry: true } });
+1 -1
View File
@@ -10,7 +10,7 @@
export let config: Config;
export let query: string | null;
let error = false;
const error = false;
onMount(async () => {
if (query) {
+3 -3
View File
@@ -47,8 +47,8 @@
const onSubmit = async () => {
state = State.Checking;
let domain = `${name}.${config.registrar.domain}`;
let resolved = await config.provider.resolveName(domain);
const domain = `${name}.${config.registrar.domain}`;
const resolved = await config.provider.resolveName(domain);
if (resolved && isAddressEqual(resolved, entity.address)) {
try {
@@ -58,7 +58,7 @@
state = State.Proposed;
} else {
state = State.Signing;
let tx = await entity.setName(domain, config);
const tx = await entity.setName(domain, config);
state = State.Pending;
await tx.wait();
state = State.Success;