I think we should start using the standard discourse code formatting for our plugin ecosystem, both for server side and client side code.
How to format whole of the plugin’s code quickly?
From your core discourse directory, run the following commands:
Client Side:
List all eslint related issues
yarn eslint --ext .js,.js.es6 plugins/discourse-ratings/assets/javascripts
Fix all eslint related issues
yarn eslint --ext .js,.js.es6 --fix plugins/discourse-ratings/assets/javascripts
List all the linting issues in client js code directories
yarn prettier --check "plugins/discourse-ratings/{assets, config}/**"
List all the js files that are not formatted correctly
yarn prettier --list-different "plugins/discourse-ratings/{assets, config}/**"
Fix all the linting issues with js files in your assets
and config
folders.
yarn prettier --write "plugins/discourse-ratings/{assets, config}/**"
Note: assets and config folder are the only valid targets for client side code linting in case of discourse.
List all the issues with your handlesbars(.hbs only) code
yarn ember-template-lint --no-ignore-pattern plugins/discourse-ratings
You can use the --verbose flag which will print the code which has issues in the console.
Server Side
List all the linting issues in server code
bundle exec rubocop plugins/discourse-ratings/
List target files in a path
bundle exec rubocop -L plugins/discourse-ratings/
Fix all the issues (only safe)
bundle exec rubocop -a plugins/discourse-ratings/
Fix all the issues (safe and unsafe)
bundle exec rubocop -A plugins/discourse-ratings/
Note: the unsafe option will replace the code which is equivalent but not semantically similar. The best course of action would be to run tests after using the unsafe option or use your judgement. More on autocorrect here
Note: using bundle exec ensures that rubocop is being run with discourse project’s config
General Workflow Guidelines
- Always commit your code before running these tools especially when running on bigger chunks of code or multiple files, so that you can go back to the actual state.