Skip to content

rename prettier command to format/reenable prettier in CI#132

Closed
scott-silver wants to merge 2 commits intomainfrom
silver/fix-prettier-command
Closed

rename prettier command to format/reenable prettier in CI#132
scott-silver wants to merge 2 commits intomainfrom
silver/fix-prettier-command

Conversation

@scott-silver
Copy link
Copy Markdown
Contributor

@scott-silver scott-silver commented Jan 25, 2022

The script alias that we have for prettier shadows the name of the library itself:

# package.json
  "scripts": {
    // ...
    "prettier": "prettier --ignore-unknown --write",

So if you wanted to do a check for any files that do not pass prettier, and you ran yarn run prettier --check ., the actual command that would run would be prettier --ignore-unknown --write --check .

Screen Shot 2022-01-25 at 2 19 35 PM

That's what's happening with the Github Action command in run-prettier.yaml. Adding the --write flag means that this command doesn't exit with status 1 when there are un-prettified files, so the check always passes.

Basically, we haven't been enforcing that prettier is run, so we have a bunch of pending prettier changes.

If we rename this script to anything other than prettier (I've used format, but I'm open to suggestions), then the Github Action will actually start enforcing that we're using prettier.

Alternatively, we could just delete prettier.

My general perception is that it has been more of a nuisance than a help. This change is going to make it a much bigger nuisance, since we'll actually start enforcing that it's been used before merging.

artifact: scenario-results # Artifact name
name: Scenario Tests # Name of the check run which will be created
path: 'scenario-results.json' # Path to test results (inside artifact .zip)
reporter: mocha-json # Format of test results
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one looks a little opposite of prettier

```js
const comet = new web3.eth.Contract(abiJson, contractAddress);
await comet.methods.absorb("0xUnderwaterAddress...").send();
await comet.methods.absorb('0xUnderwaterAddress...').send();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like some of these (like this one), but others are kind of meh. Maybe the answer is to dial down the rules a bit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, we can definitely disable some of the rules.

Prettier deliberately limits how much you can configure it (https://prettier.io/docs/en/option-philosophy.html), so there will be a limit to how much we can dial it down.

The other option would be to start using something like ESLint instead. It might give us better control over defining the style that we want our files to conform to, and a little more flexibility in terms of where we add line breaks, put comments, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I suppose we should add it back, maybe after we merge the current round of other outstanding PRs though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, no hurry

"lint-contracts": "solhint 'contracts/**/*.sol'",
"lint-contracts:fix": "solhint --fix 'contracts/**/*.sol'",
"prettier": "prettier --ignore-unknown --write",
"format": "prettier --ignore-unknown --write",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch 🎣

async function asAddresses(contract: Contract, fnName: string): Promise<Address[]> {
if (fnName.startsWith('%')) { // Read from slot
if (fnName.startsWith('%')) {
// Read from slot
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one's a little obnoxious

throw new Error(`Cannot find contract function ${contract.name}.${fnName}()`);
}
let val = (await fn());
let val = await fn();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good one

`Could not find contract ${targetContract} in buildFile with contracts: ${JSON.stringify(
Object.keys(contracts)
)}`
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Longer lines would get rid of this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, I might die trying to handle this merge, since this file has been totally rewritten.

function bindFunctions(obj: any) {
for (let property of Object.getOwnPropertyNames(Object.getPrototypeOf(obj))) {
if (typeof(obj[property]) === 'function') {
if (typeof obj[property] === 'function') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Controversial maybe

function?: string;
file?: string;
line?: number;
char?: number;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

let index = 0;

while (null != (next=regex.exec(stack))) {
while (null != (next = regex.exec(stack))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good one

@scott-silver scott-silver changed the title rename prettier command to format rename prettier command to format/reenable prettier in CI Jan 25, 2022
@hayesgm
Copy link
Copy Markdown
Contributor

hayesgm commented Jan 31, 2022

Out of curiousity, why not just run npx prettier ... which wouldn't run the script command, right?

@scott-silver
Copy link
Copy Markdown
Contributor Author

@hayesgm yep, that would work, too. we could also reference the npm module directly:

./node_modules/prettier/bin-prettier.js --check .

I opted to change the command because the error would anywhere someone ran yarn prettier; seemed like surprising behavior.

The more I've thought about it, the more I think ESLint might be a better fit for us.

Prettier seems like it's well-suited to large teams with developers of varying skill levels. We have a small team of senior people. I think the customizability of ESLint might be more appropriate.

Copy link
Copy Markdown
Contributor

@hayesgm hayesgm left a comment

Choose a reason for hiding this comment

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

Looks great; biggest concern is can we wait for a few larger PRs to drop before we merge this? Just going to be a big conflict with some of the files that are coming in.

@scott-silver
Copy link
Copy Markdown
Contributor Author

closing for now

@jflatow
Copy link
Copy Markdown
Contributor

jflatow commented Mar 31, 2022

we don't still want to do this eventually?

@jflatow jflatow deleted the silver/fix-prettier-command branch May 26, 2022 05:15
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