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

Lint #4276

Merged
merged 45 commits into from
May 6, 2021
Merged

Lint #4276

Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d138202
Lint
yakov116 Apr 25, 2021
7e4e39d
Move `get-current-committish` to its own file
yakov116 Apr 25, 2021
8f10741
Some more lint
yakov116 Apr 25, 2021
bb28903
Fix some more types
yakov116 Apr 26, 2021
d5a06d1
Revert `.closest`
yakov116 Apr 26, 2021
3ca191d
Fix 2 more
yakov116 Apr 26, 2021
45242b1
Make the tests pass for now
yakov116 Apr 26, 2021
a0e618e
Fix some types
fregante Apr 26, 2021
02c9672
Hack it
yakov116 Apr 27, 2021
0075d18
Fix one more
yakov116 Apr 27, 2021
55cb73a
Restore convert-release-to-draft.tsx
yakov116 Apr 27, 2021
5bc6a8b
Restore file-finder-buffer.tsx
yakov116 Apr 27, 2021
1d04c6e
Restore index.tsx
yakov116 Apr 27, 2021
3d657a1
Restore options.tsx
yakov116 Apr 27, 2021
44d1aa6
Small type fix
yakov116 Apr 27, 2021
b0b3166
Revert `fix-teaxtarea`
yakov116 Apr 27, 2021
3461b7e
unicorn/expiring-todo-comments: warn
yakov116 Apr 27, 2021
e2314fe
Merge remote-tracking branch 'upstream/main' into lint
yakov116 Apr 27, 2021
60de2e8
Fix something (`vertical-font-matter`)
yakov116 Apr 27, 2021
84f530e
...
yakov116 Apr 27, 2021
4000ffa
Disable no-redeclare
yakov116 Apr 27, 2021
72bd7f2
Lint
yakov116 Apr 27, 2021
0de745d
Update tsconfig
yakov116 Apr 28, 2021
1d1fb09
Revert "Fix something (`vertical-font-matter`)"
yakov116 Apr 27, 2021
b8bee86
update typed-query-selector
yakov116 Apr 28, 2021
ee7a3cf
Revert tsconfig
yakov116 Apr 28, 2021
228ec96
Restore tsconfig.json
yakov116 Apr 28, 2021
265c8fa
convert to yml
yakov116 May 4, 2021
3116544
Merge branch 'main' into lint
yakov116 May 4, 2021
32af8df
Revert "convert to yml"
yakov116 May 4, 2021
b775d52
Correct Type
yakov116 May 4, 2021
a2cf78c
And some more
yakov116 May 4, 2021
d97d253
Restore .xo-config.json
yakov116 May 4, 2021
d2d5c0d
Update
yakov116 May 4, 2021
2215257
Update excluding xo
yakov116 May 4, 2021
c2b4f6d
Restore quick-repo-deletion.tsx
yakov116 May 4, 2021
d83acea
Lint
yakov116 May 4, 2021
37b5734
Restore globals.d.ts
yakov116 May 5, 2021
43c007a
Restore vertical-front-matter.tsx
yakov116 May 5, 2021
05cf4ad
Update some more
yakov116 May 5, 2021
3761225
Restore mark-merge-commits-in-list.tsx
yakov116 May 6, 2021
22b4592
Merge remote-tracking branch 'upstream/lint' into lint
yakov116 May 6, 2021
0c93073
One last attempt at the types
yakov116 May 6, 2021
a87d50d
Disable `clean-conversation-sidebar`
fregante May 6, 2021
db29dba
Restore list-prs-for-file.tsx
fregante May 6, 2021
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
2 changes: 2 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"no-void": "off",
"react/jsx-key": "off",
"unicorn/no-array-callback-reference": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
Copy link
Member

Choose a reason for hiding this comment

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

What's the problem again? It worked until now and typescript-eslint/typescript-eslint#1976 was resolved

Copy link
Member Author

@yakov116 yakov116 Apr 25, 2021

Choose a reason for hiding this comment

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

Same issue, XO re enabled the rule now.

Disabled "@typescript-eslint/no-non-null-asserted-optional-chain" See #3093 (comment) and #3168 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

If Sindre re-enabled them they're probably working now, so maybe our code is wrong.

The only reason I can think of to disable these are if the changes required just clutter the code without actually improving it

Copy link
Member

Choose a reason for hiding this comment

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

@typescript-eslint/no-non-null-assertion is correct in being disabled, we need those errors.

I'm checking the other one

Copy link
Member

Choose a reason for hiding this comment

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

@typescript-eslint/no-non-null-asserted-optional-chain should probably not be disabled.

However I'm not liking most of the type changes in this PR so I'd rather avoid all of them until a TS developer can review them properly.

If you're going to update XO:

  • disable no-unsafe-argument + a TODO to review later
  • disable no-non-null-asserted-optional-chain + same TODO
  • disable no-non-null-assertion with a comment that we need those runtime errors

Copy link
Member Author

Choose a reason for hiding this comment

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

@fregante in case you missed this comment

Copy link
Member

@fregante fregante May 4, 2021

Choose a reason for hiding this comment

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

Find a JSON to YML converter and rename the file to .yml instead of .json

Copy link
Member Author

@yakov116 yakov116 May 4, 2021

Choose a reason for hiding this comment

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

That did not work.

I am going to revert the Type's and just update dep excluding xo

Copy link
Member

Choose a reason for hiding this comment

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

You're right, I assumed it worked since ESLint supports it: xojs/xo#536

Copy link
Member

Choose a reason for hiding this comment

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

We are using a JSON file which makes it not possible to leave a comment.

That's not entirely true: https://github.com/sindresorhus/sindre-playground/blob/565ba9c61dbf4b13d587bcae7047120952f924c5/package.json#L26-L31

"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-function-return-type": [
Expand Down
689 changes: 268 additions & 421 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"js-abbreviation-number": "^1.1.2",
"linkify-issues": "2.0.0-nolookbehind",
"linkify-urls": "3.1.0-nolookbehind",
"mem": "^8.1.0",
"mem": "^8.1.1",
"one-event": "^3.0.0",
"one-mutation": "^2.0.0",
"onetime": "^6.0.0",
Expand All @@ -82,23 +82,23 @@
"webext-dynamic-content-scripts": "^7.1.1",
"webext-options-sync-per-domain": "^2.0.2",
"webext-storage-cache": "^4.2.0",
"webextension-polyfill": "^0.7.0",
"webextension-polyfill": "^0.8.0",
"zip-text-nodes": "^1.0.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@sindresorhus/tsconfig": "^0.9.0",
"@types/chrome": "^0.0.134",
"@types/codemirror": "^0.0.108",
"@types/copy-webpack-plugin": "^6.4.1",
"@types/chrome": "^0.0.135",
"@types/codemirror": "^0.0.109",
"@types/copy-webpack-plugin": "^8.0.0",
"@types/firefox-webext-browser": "^82.0.0",
"@types/jsdom": "^16.2.10",
"@types/mini-css-extract-plugin": "^1.4.1",
"@types/mini-css-extract-plugin": "^1.4.2",
"@types/react": "^17.0.3",
"@types/terser-webpack-plugin": "^5.0.3",
"ava": "^3.15.0",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.0",
"css-loader": "^5.2.4",
"daily-version": "^2.0.0",
"dot-json": "^1.2.2",
"esbuild-loader": "^2.11.0",
Expand All @@ -110,15 +110,15 @@
"mini-css-extract-plugin": "^1.4.1",
"npm-run-all": "^4.1.5",
"size-plugin": "^2.0.2",
"stylelint": "^13.12.0",
"stylelint": "^13.13.0",
"stylelint-config-xo": "^0.20.0",
"terser-webpack-plugin": "^5.1.1",
"ts-node": "^9.1.1",
"tslib": "^2.2.0",
"type-fest": "^0.21.3",
"type-fest": "^1.0.2",
"typed-query-selector": "^2.5.3",
"typescript": "^4.2.4",
"webpack": "^5.31.0",
"webpack": "^5.35.1",
"webpack-cli": "^4.6.0",
"xo": "^0.38.2"
},
Expand Down
4 changes: 2 additions & 2 deletions source/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const messageHandlers = {
}
};

browser.runtime.onMessage.addListener((message, sender) => {
for (const id of Object.keys(message ?? {}) as Array<keyof typeof messageHandlers>) {
browser.runtime.onMessage.addListener((message: typeof messageHandlers, sender) => {
for (const id of Object.keys(message) as Array<keyof typeof messageHandlers>) {
if (id in messageHandlers) {
return messageHandlers[id](message[id], sender);
}
Expand Down
4 changes: 2 additions & 2 deletions source/features/avoid-accidental-submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function addQuickSubmit(): void {
select('input#commit-summary-input')!.classList.add('js-quick-submit');
}

function onKeyDown(event: delegate.Event<KeyboardEvent, HTMLFormElement>): void {
function onKeyDown(event: delegate.Event<KeyboardEvent, HTMLInputElement>): void {
if (event.key === 'Enter' && !event.ctrlKey) {
event.preventDefault();
select('#issue_body, #pull_request_body, #commit-description-textarea', event.delegateTarget.form)!.focus();
select('#issue_body, #pull_request_body, #commit-description-textarea', event.delegateTarget.form!)!.focus();
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/features/comments-time-machine-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function showTimemachineBar(): Promise<void | false> {
'.repository-content .Box.Box--condensed relative-time',
'[itemprop="dateModified"] relative-time' // "Repository refresh" layout
].join(), {waitForChildren: false});
if (date > lastCommitDate?.attributes.datetime.value!) {
if (lastCommitDate && date > lastCommitDate.getAttribute('datetime')!) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion source/features/convert-release-to-draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function convertToDraft({delegateTarget: draftButton}: delegate.Event): Pr

const tagName = location.pathname.split('/').pop()!;
const release = await api.v3(`releases/tags/${tagName}`);
await api.v3(release.url, {
await api.v3(String(release.url), {
method: 'PATCH',
body: {
draft: true
Expand Down
2 changes: 1 addition & 1 deletion source/features/file-finder-buffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getBufferField = onetime((): HTMLInputElement => (
));

function pjaxStartHandler(event: CustomEvent): void {
const destinationURL = event.detail?.url;
const destinationURL: string = event.detail?.url;
fregante marked this conversation as resolved.
Show resolved Hide resolved
if (!destinationURL || !pageDetect.isFileFinder(new URL(destinationURL))) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion source/features/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const checkForHotfixes = cache.function(async () => {

// eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- https://github.com/typescript-eslint/typescript-eslint/issues/1893
if (hotfixes && hotfixes.unaffected) {
const currentVersion = browser.runtime.getManifest().version;
const currentVersion: string = browser.runtime.getManifest().version;
if (compareVersions(hotfixes.unaffected, currentVersion) < 1) {
return {};
}
Expand Down
12 changes: 11 additions & 1 deletion source/features/latest-tag-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ interface RepoPublishState {
aheadBy?: number;
}

interface Tags {
name: string;
tag: {
oid: string;
commit?: {
oid: string;
};
};
}

const getRepoPublishState = cache.function(async (): Promise<RepoPublishState> => {
const {repository} = await api.v4(`
repository() {
Expand Down Expand Up @@ -58,7 +68,7 @@ const getRepoPublishState = cache.function(async (): Promise<RepoPublishState> =
}

const tags = new Map<string, string>();
for (const node of repository.refs.nodes) {
for (const node of repository.refs.nodes as Tags[]) {
tags.set(node.name, node.tag.commit?.oid ?? node.tag.oid);
}

Expand Down
7 changes: 6 additions & 1 deletion source/features/link-to-changelog-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import features from '.';
import * as api from '../github-helpers/api';
import {buildRepoURL, getRepo} from '../github-helpers';

interface FileType {
name: string;
type: string;
}

const getCacheKey = (): string => `changelog:${getRepo()!.nameWithOwner}`;
const changelogNames = new Set(['changelog', 'news', 'changes', 'history', 'release', 'whatsnew']);

Expand Down Expand Up @@ -43,7 +48,7 @@ const getChangelogName = cache.function(async (): Promise<string | false> => {
`);

const files: string[] = [];
for (const entry of repository.object.entries) {
for (const entry of repository.object.entries as FileType[]) {
if (entry.type === 'blob') {
files.push(entry.name);
}
Expand Down
2 changes: 1 addition & 1 deletion source/features/list-prs-for-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getSingleButton(prNumber: number, _?: number, prs?: number[]): HTMLElem
const getPrsByFile = cache.function(async (): Promise<Record<string, number[]>> => {
const {repository} = await api.v4(`
repository() {
pullRequests(
pullRequests (
Copy link
Member

Choose a reason for hiding this comment

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

^

Copy link
Member Author

Choose a reason for hiding this comment

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

I added on purpose it looked wrong without a space and the arguments on a new line.

I can revert if you feel it wrong

Copy link
Member

Choose a reason for hiding this comment

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

We don't do this anywhere in the code and also doesn't match the function call style in XO. Reverted

first: 25,
states: OPEN,
baseRefName: "${await getDefaultBranch()}",
Expand Down
2 changes: 1 addition & 1 deletion source/features/mark-merge-commits-in-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const filterMergeCommits = async (commits: string[]): Promise<string[]> => {
`);

const mergeCommits = [];
for (const [key, commit] of Object.entries<AnyObject>(repository)) {
for (const [key, commit] of Object.entries(repository as AnyObject)) {
if (commit.parents.totalCount >= 2) {
mergeCommits.push(key.slice(1));
}
Expand Down
2 changes: 1 addition & 1 deletion source/features/next-scheduled-github-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getScheduledWorkflows = cache.function(async (): Promise<Record<string, st

const schedules: Record<string, string> = {};
for (const workflow of workflows) {
const workflowYaml = workflow.object.text;
const workflowYaml = String(workflow.object.text);
const name = /^name[:\s'"]+([^'"\n]+)/m.exec(workflowYaml);
const cron = /schedule[:\s-]+cron[:\s'"]+([^'"\n]+)/m.exec(workflowYaml);

Expand Down
2 changes: 1 addition & 1 deletion source/features/quick-repo-deletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function buttonTimeout(buttonContainer: HTMLDetailsElement): Promise<boole
buttonContainer.addEventListener('toggle', () => {
abortController.abort();
}, {once: true});

// eslint-disable-next-line promise/prefer-await-to-then
void api.expectTokenScope('delete_repo').catch((error: Error) => {
abortController.abort();
buttonContainer.open = false;
Expand Down
11 changes: 8 additions & 3 deletions source/features/release-download-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {abbreviateNumber} from 'js-abbreviation-number';
import features from '.';
import * as api from '../github-helpers/api';

interface ReleaseAssets {
releaseAssets: {
nodes: Asset[];
};
}
interface Asset {
name: string;
downloadCount: number;
Expand All @@ -31,15 +36,15 @@ async function getAssetsForTag(tags: string[]): Promise<Tag> {
`);

const assets: Tag = {};
fregante marked this conversation as resolved.
Show resolved Hide resolved
for (const [tag, release] of Object.entries(repository)) {
assets[tag] = (release as AnyObject).releaseAssets.nodes;
for (const [tag, release] of Object.entries(repository as ReleaseAssets[])) {
fregante marked this conversation as resolved.
Show resolved Hide resolved
assets[tag] = release.releaseAssets.nodes;
}

return assets;
}

async function init(): Promise<void | false> {
const releases = new Map();
const releases = new Map<string, HTMLElement>();
for (const release of select.all('.release')) {
if (select.exists('.octicon-package', release)) {
const name = select('svg.octicon-tag ~ span', release)!.textContent!;
Expand Down
13 changes: 11 additions & 2 deletions source/features/repo-age.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import features from '.';
import * as api from '../github-helpers/api';
import {getRepo} from '../github-helpers';

interface CommitTarget {
oid: string;
committedDate: string;
resourcePath: string;
history: {
totalCount: number;
};
}

const fresh = [
'Freshly baked',
'Freshly brewed',
Expand Down Expand Up @@ -50,7 +59,7 @@ const getRepoAge = async (commitSha: string, commitsCount: number): Promise<[com
const {committedDate, resourcePath} = repository.defaultBranchRef.target.history.nodes
.reverse()
// Filter out any invalid commit dates #3185
.find((commit: AnyObject) => new Date(commit.committedDate).getFullYear() > 1970);
.find((commit: CommitTarget) => new Date(commit.committedDate).getFullYear() > 1970);

return [committedDate, resourcePath];
};
Expand All @@ -73,7 +82,7 @@ const getFirstCommit = cache.function(async (): Promise<[committedDate: string,
}
`);

const {oid: commitSha, history, committedDate, resourcePath} = repository.defaultBranchRef.target;
const {oid: commitSha, history, committedDate, resourcePath} = repository.defaultBranchRef.target as CommitTarget;
const commitsCount = history.totalCount;
if (commitsCount === 1) {
return [committedDate, resourcePath];
Expand Down
7 changes: 5 additions & 2 deletions source/features/show-associated-branch-prs-on-fork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import * as api from '../github-helpers/api';
import {getRepo, upperCaseFirst} from '../github-helpers';

interface PullRequest {
timelineItems: {
nodes: AnyObject;
};
number: number;
state: keyof typeof stateClass;
isDraft: boolean;
Expand Down Expand Up @@ -42,11 +45,11 @@ const getPullRequestsAssociatedWithBranch = cache.function(async (): Promise<Rec

const pullRequests: Record<string, PullRequest> = {};
for (const {name, associatedPullRequests} of repository.refs.nodes) {
const [prInfo] = associatedPullRequests.nodes;
const [prInfo] = associatedPullRequests.nodes as PullRequest[];
// Check if the ref was deleted, since the result includes pr's that are not in fact related to this branch but rather to the branch name.
const headRefWasDeleted = prInfo?.timelineItems.nodes[0]?.__typename === 'HeadRefDeletedEvent';
if (prInfo && !headRefWasDeleted) {
prInfo.state = prInfo.isDraft && prInfo.state === 'OPEN' ? 'Draft' : upperCaseFirst(prInfo.state);
prInfo.state = prInfo.isDraft && upperCaseFirst(prInfo.state) === 'Open' ? 'Draft' : upperCaseFirst(prInfo.state) as keyof typeof stateClass;
fregante marked this conversation as resolved.
Show resolved Hide resolved
pullRequests[name] = prInfo;
}
}
Expand Down
6 changes: 5 additions & 1 deletion source/features/stop-redirecting-in-notification-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import delegate from 'delegate-it';

import features from '.';

interface SessionStorage extends Storage {
notification_shelf: string;
}

const hasNotificationBar = (): boolean =>
location.search.startsWith('?notification_referrer_id=') ||
JSON.parse(sessionStorage.notification_shelf ?? '{}').pathname === location.pathname;
JSON.parse((sessionStorage as SessionStorage).notification_shelf ?? '{}').pathname === location.pathname;
yakov116 marked this conversation as resolved.
Show resolved Hide resolved

function handleClick(event: delegate.Event<MouseEvent, HTMLButtonElement>): void {
// Disable the redirect to the Notifications inbox if either:
Expand Down
7 changes: 4 additions & 3 deletions source/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import domify from 'doma';
import select from 'select-dom';
import delegate from 'delegate-it';
import fitTextarea from 'fit-textarea';
import {JsonObject} from 'type-fest';
import * as indentTextarea from 'indent-textarea';

import {perDomainOptions} from './options-storage';
Expand Down Expand Up @@ -53,8 +54,8 @@ async function getTokenScopes(personalToken: string): Promise<string[]> {
});

if (!response.ok) {
const details = await response.json();
throw new Error(details.message);
const details: JsonObject = await response.json();
throw new Error(String(details.message));
fregante marked this conversation as resolved.
Show resolved Hide resolved
}

const scopes = response.headers.get('X-OAuth-Scopes')!.split(', ');
Expand Down Expand Up @@ -157,7 +158,7 @@ function featuresFilterHandler(event: Event): void {

async function highlightNewFeatures(): Promise<void> {
const {featuresAlreadySeen} = await browser.storage.local.get({featuresAlreadySeen: {}});
const isFirstVisit = Object.keys(featuresAlreadySeen).length === 0;
const isFirstVisit = Object.keys(featuresAlreadySeen as AnyObject).length === 0;
const tenDaysAgo = Date.now() - (10 * 24 * 60 * 60 * 1000);

for (const feature of select.all('.feature [type=checkbox]')) {
Expand Down
Loading