Commit Graph

7 Commits

Author SHA1 Message Date
Hannah Wolfe
2f1123d6ca
Added eslint rule to prevent usage of new Error()
- we have our own error library that should always be used to wrap errors in useful info
- therefore instead of new Error() we should always be using errors.SomeError from @tryghost/error
2021-06-08 11:51:49 +01:00
Hannah Wolfe
576f1438ee
Upgraded no-restricted-require in shared rule to error
- We should not require server or frontend files inside the shared libraries as these are intended to be required FROM the server and frontend components
- Now that we've resolved the two outstanding warnings, make this an error so we can't regress on this easily
2021-05-26 12:35:49 +01:00
Hannah Wolfe
8cff7b9cd6
Added length rule for index files [warn]
- index.js files are meant to be an index, not contain behaviour or logic
- files longer than 50 lines are indicative of code in the wrong place, all though not definitive
- enabling this as a hint to get us to move code to better locations
2021-05-07 21:00:39 +01:00
Hannah Wolfe
ba6f51850e
Added complexity rule for api query methods [warn]
- We want to keep behaviour in services and libraries, not in API endpoints
- This rule runs complexity _only_ on the query methods, and has it set super low - just 3
- Methods that have higher complexity are a great indicator of places where we've left behaviour in the API, however!
- It's indicative, not definitive. At least with an eslint rule we can if needs be disable it where we decide the code is OK
2021-05-07 20:41:14 +01:00
Hannah Wolfe
2e5977a137
Added require rules for server<>frontend [off]
- These rules will help us to enforce that server code should not be required from the frontend, and vice versa
- They are disabled/off for now because they are too noisy and not quick to fix
- Having them in place makes it easy to set them to warn to preview how we're getting on with fixing them ahead of enabling them
2021-05-07 20:25:50 +01:00
Hannah Wolfe
781cc6f304
Switched to eslint-plugin-node + fix eslint test perf
refs: https://github.com/TryGhost/Ghost/commit/7bce05ab8

- I wrote a custom plugin for the no-cross-requires logic between our modules after not finding anything that could do it
- Then, when searching for the next rule I wanted, I found eslint-plugin-ghost has no-restricted-requires
- This rule is more flexible, so switching to it
- NOTE: This update to eslint-plugin-ghost also fixes performance of linting our test files by pinning eslint-plugin-mocha to v7 as v8 has performance problems
2021-05-07 13:25:18 +01:00
Hannah Wolfe
d2c6838133
Switched to using .js files for eslint
- Using JS files to configure eslint gives us more power, e.g. being able to calculate paths
- We already use JS in pretty much every other repo we own, including admin... it's just Ghost we don't, and it's time!
2021-05-07 10:30:41 +01:00