I just wrote a PR that didn’t pass the Travis tests due to linting issues. I couldn’t find any entries in meta that discussed eslinting/prettier, so I went digging around the code and found out how to improve my code to fit with the styling and listing standards of Discourse. This may be useful for others, so here’s a log of what I did:
First, to install ESLint and prettier locally. I ran:
and that installed all the dev dependencies listed in
package.json. Depending on which part of Discourse you’re working on, you may need to run one of these commands to check for issues:
I was working on an improvement to core, so the first line above found my issues. When ESLint finds an error, the output is fairly clear, for example I got something like this:
I fixed the issue by removing the unused variable, and then ESLint passed on a second try.
Prettier is similar. In
lib/tasks/docker.rake, I found the following command:
This showed me the filenames for which prettier found formatting offenses. To fix them, I ran:
yarn prettier [filename] --write
After running that command for the 2-3 files that had issues, I committed, pushed, and waited for Travis to pass (thankfully, it did!).
For Ruby linting, see Rubocop has landed on Discourse 👮♀️ 👮
For a more automated way to integrate ESLint and Prettier with your edit, see