Skip to content

Conversation

@davidyuk
Copy link
Member

This PR is supported by the Æternity Foundation

The idea is to use Eslint for sophisticated checks (I'm not sure that it is needed in this project) and Prettier for code formatting since it works faster. I would drop AirBnb rules because they have not been maintained for a couple of years. I also like that Prettier formats JS in MD files.

https://prettier.io/docs/options

Copy link
Member

@dincho dincho left a comment

Choose a reason for hiding this comment

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

Hard to review as the GH UI almost crashes, but managed to post few comments. In general the code style is tough question.

let _
if (isObject(key)) {
[[key, _]] = Object.entries(key)
;[[key, _]] = Object.entries(key)
Copy link
Member

Choose a reason for hiding this comment

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

What?

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 also didn't expect that 😁 There are edge cases when you are required to add a semicolon. Prettier doesn't detect them accurately. They claim it is made to move lines of code freely: prettier/prettier#1907.

The most popular semicolon-less eslint ruleset also enforces these extra semicolons: https://standardjs.com/rules.html#semicolons

signature: {tag: 'sg', size: 64, encoder: base58check},
commitment: {tag: 'cm', size: 32, encoder: base58check},
bytearray: {tag: 'ba', size: 0, encoder: base64check},
key_block_hash: { tag: 'kh', size: 32, encoder: base58check },
Copy link
Member

Choose a reason for hiding this comment

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

I definitely disagree with this extra space

Copy link
Member Author

Choose a reason for hiding this comment

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

There was no consistency, and I think I've chosen the more popular variant to reduce the diff, but I'll do as you prefer.

const { symbols } = this._bytecode

return Object.keys(symbols).find(key => symbols[key] === funName)
return Object.keys(symbols).find((key) => symbols[key] === funName)
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with forcing non-mandatory () here, mainly because of readability

Copy link
Member Author

Choose a reason for hiding this comment

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

There was no consistency, and I think I've chosen the more popular variant to reduce the diff, but I'll do as you prefer.

'bls12_381.fr',
'bls12_381.fp',
]
const TYPES = ['bls12_381.fr', 'bls12_381.fp']
Copy link
Member

Choose a reason for hiding this comment

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

I definitely prefer multiline list both for readability and maintenance regardless if it fits on line limit

Copy link
Member

Choose a reason for hiding this comment

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

However, single line should be also allowed as it works better in some code blocks/snippets

Copy link
Member Author

@davidyuk davidyuk Mar 28, 2025

Choose a reason for hiding this comment

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

Prettier keep line breaks but only in objects: https://prettier.io/docs/rationale#multi-line-objects (and they consider this a bug)
The are only workarounds like prettier-ignore or adding an empty comment 🙁

// prettier-ignore
const TYPES = [ //
  'bls12_381.fr',
  'bls12_381.fp'
]

FateTypeRecord(type.keys, type.valueTypes),
resolvedValue
)
return new FateTuple(FateTypeRecord(type.keys, type.valueTypes), resolvedValue)
Copy link
Member

Choose a reason for hiding this comment

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

Single line shouldn't be enforced in this case as well

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no good way to implement this: we can reduce printWidth or add a comment as the above 🤷‍♀️


create(type, value) {
if (!Array.isArray(value)) {
throw new FateTypeError(
Copy link
Member

Choose a reason for hiding this comment

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

again, enforced single line which I don't like

prettier.cjs Outdated
// don't collapse function call if multiline
.replaceAll(/ (\w+)\(\n/g, ` $1(\n${comment}\n`)
// don't collapse array definition if multiline
.replaceAll(/ \[\n/g, ` [\n${comment}\n`)
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've tried to rewrite files on the fly to prevent array and fn call collapsing, and this seems to be working

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.

3 participants