Integrade code formatting specifications into the GRNsight repo
The latest code formatters are getting better at formatting code in a reliable and consistent manner. Some implications in case we adopt this for GRNsight:
- We will want to configure the code formatter in a manner that use a style that the team agrees upon
- There will be a “formatting-only” transition phase where the code formatter may need to make a wide array of edits in order to sync up the code to the latest style
Formatter for consideration: https://prettier.io
Set up repo so that independently of the code editor being used. Might need to reckon with 4 spaces of indenting vs new standard for javascript which is 2 spaces of indenting. Could be implemented in the GitHub Actions workflow.
Prettier has established itself as the de facto code-formatter for many repos, so we will just go with that. We will need a .prettierrc file (or similar mechanism) on the repo, and make sure that our editors are configured to use it
If we change format, step (2) in the original description may still need to take place
With the merging of #1148 into beta, we now need to observe interactions between Prettier and ESLint and can finalize configurations based on that
Prettier Integration
-
Created .prettierrc.js aligned with Grnsight's style: 4-space indentation Double quotes for strings Consistent semicolons Standardized object formatting
-
Then Integrated ESLint and Prettier to avoid style conflicts. Added prettier dependencies
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettierReally cool -->eslint-config-prettier: Disables ESLint rules that conflict with Prettiereslint-plugin-prettier:Runs Prettier as an ESLint rule -
Updated ESLint Config for Prettier Integration
-
Add formatting scripts to packjson
-
Added to the scripts (formatting)
"scripts": {
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,json,md}\"",
"lint": "eslint \"**/*.js\"",
"lint:fix": "eslint --fix \"**/*.js\""
}
Formatting
To format use the command npm run format
To check for formatting issues use the command npm run format:check
Lastly I ran npm run lint and received errors regarding the depricated .eslintignore file and unused eslint-disable directives.
- Updated eslint.config.js file to include all ignored files and removed eslintignore file
- Cleaned up unused eslint-disable directives using
npx eslint --fix .
On track to push the PR with these changes
This ticket can also be closed alongside #1147 once that is verified
Closing per comment above that it can be closed alongside #1147, which is now closed.