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 & fix #1808

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

lint & fix #1808

wants to merge 12 commits into from

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Jan 6, 2025

Proposal to add a permissive eslint config that catches some issues while also making the sndev coding style pass.
All deps are devDependencies. Usage is npm run eslint.

I fixed all the issues unrelated to coding style, that were just dead code, unused imports, wrong react pops and a potential global shadowing that did not cause any issue yet.

It would probably be useful to add graphql-eslint plugin, but i couldn't figure out how to provide the schema that it needs.

@@ -102,7 +102,6 @@ export async function onPaid ({ invoice, actIds }, { tx }) {
}
})
acts = await tx.itemAct.findMany({ where: { invoiceId: invoice.id }, include: { item: true } })
actIds = acts.map(act => act.id)
Copy link
Member Author

Choose a reason for hiding this comment

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

dead code?

Copy link

socket-security bot commented Jan 6, 2025

@@ -16,7 +16,7 @@ export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) {

return (
<span
className='text-monospace' style={{ whiteSpace: 'pre-wrap' }} align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)}
className='text-monospace' style={{ whiteSpace: 'pre-wrap', textAlign: 'right' }} onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)}
Copy link
Member Author

Choose a reason for hiding this comment

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

this is probably how it was intended, but this entire file looks like it is not being used anymore

let variant = 'default'
let status = 'waiting for you'
let variant
let status
Copy link
Member Author

Choose a reason for hiding this comment

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

other defaults are set in the else block

@@ -62,7 +62,7 @@ function ErrorImage ({ statusCode }) {
return <Image className='rounded-1 shadow-sm' width='500' height='376' src={`${process.env.NEXT_PUBLIC_ASSET_PREFIX}/falling.gif`} fluid />
}

export default function Error ({ statusCode }) {
export default function ErrorPage ({ statusCode }) {
Copy link
Member Author

@riccardobl riccardobl Jan 6, 2025

Choose a reason for hiding this comment

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

was a potential global shadowing inside this file

logger = walletLogger({ wallet, models })
bolt11 = invoice
const logger = walletLogger({ wallet, models })
const bolt11 = invoice
Copy link
Member Author

@riccardobl riccardobl Jan 6, 2025

Choose a reason for hiding this comment

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

if the only thing the catch does is logging the error and rethrow, there is no point in wrapping all the rest of the code in the try-catch, also eslint didn't like this.

@riccardobl riccardobl marked this pull request as ready for review January 6, 2025 15:45
Copy link
Member

@huumn huumn left a comment

Choose a reason for hiding this comment

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

This looks like it caught some stuff (largely inconsequential from the looks of it, but they'd confuse a newcomer, so nice to be rid of them).

We already have a linter (and we add a nextjs plugin) so I guess I'd be curious:

  1. which rules this is adding that we don't already have with the existing linters (the delta - do we know?)
  2. why we chose the rules that were chosen and not all the rules those plugins provide
  3. why we should implement these plugins into a separate linter rather than plugging into to the existing one

Maybe those things are obvious, but I'm not super familiar with lint rules and managing them.

@riccardobl
Copy link
Member Author

riccardobl commented Jan 10, 2025

why we should implement these plugins into a separate linter rather than plugging into to the existing one

I don't know much about standardjs, maybe it is possible to achieve the same goal in a different way, but the current setup seems to be targeted mostly at detecting formatting deviations, while the eslint config i've added here is mostly aimed at detecting oversights and bad patterns that make the code fragile or confusing.

why we chose the rules that were chosen and not all the rules those plugins provide

The suggested rules for the plugins are too strict for sn (they were finding 300+ issues) so i've disabled those that I thought were considered undesired, and those that are just outright too strict to make sense in the codebase , just by my experience with the project (no scientific method here, and might need more tweaks). I've disabled also the rules related to improving regexes, that i think are not very important, and would need some special attention.

which rules this is adding that we don't already have with the existing linters (the delta - do we know?)

the rule set is here and here, minus the ones disabled.

Ultimately my goal here was to add something to make the review process lighter by having some form of guidance to catch stylistic issues and avoid nitpicking in prs for new contributors (make the unwritten rules written), and to catch oversights from veterans.
I don't have strong opinions on whether to use eslint or other linters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants