Commit Graph

18 Commits

Author SHA1 Message Date
Sam Lord
a21b91cc71 Added lint rules for migrations
refs: https://github.com/TryGhost/Toolbox/issues/105

Lint rules prevent:

* Invalid naming conventions for new migrations
* Loop constructs in migrations - these should be used with caution
and are therefore a warning rule, use `// eslint-disable-next-line
no-restricted-syntax` to prevent this rule from firing where a loop is
required
* Returing within a loop - this is usually meant to be a
continue/break
* Multiple joins - these can be badly performing migrations, so should
be treated with caution, disable the rule for the line if the risk is
understood / the migration cannot be written without it
2021-11-29 16:21:43 +00:00
Sam Lord
e28a3769a7 Added lint warnings for bad patterns in migrations
refs: https://github.com/TryGhost/Toolbox/issues/105
The idea here is to ensure we're at least warning on bad migrations patterns. If a pattern is already in use in an existing migration, we can use `eslint-disable-next-line no-restricted-syntax` to override it. For new migrations which still need these features this step will force the user to think about the performance of the construct they are using
2021-11-29 16:21:43 +00:00
Naz
405603d530 Fixed liniting error for validators' index.js files
refs f0242baf9f

- The index.js files in "input validators" are exposing an API and not doing anything else so these cases can be safely ignored
- Ideally we'd have a solution which would export all modules in the folder without having to add any more declarations, but that's for another time!
2021-11-08 16:43:16 +04:00
Hannah Wolfe
5327eb4b4b
Upgraded api max complixity eslint rule to error
- We've now squashed all the warnings, upgrade to error to prevent regressions
2021-10-25 14:36:12 +01:00
Hannah Wolfe
df14789861
Enabled restricted require rule for core/server
- we're now so close to having the server not require anything from the frontend... so close
- having these last few problems be visible is motivating
- should be able to upgrade it to an error soooon!
2021-10-21 20:37:08 +01:00
Hannah Wolfe
ad23628279
Removed extra eslint clarifiers for restricted requires
refs: bd4000e7f

- we can remove these again now that we've done the work to get rid of the two worst offenders: lib/common/events and urlservice
- happened quicker than I expected :D
2021-10-19 18:42:23 +01:00
Hannah Wolfe
bd4000e7f7
Updated eslint to make restricted requires clearer
- url service is responsible for many problem requires, and will be removed soon
- the same with lib/common/events
- excluding these leaves us with a handful of much harder to solve requires clearly indicated
2021-10-16 19:24:42 +01:00
Hannah Wolfe
81fdde05b9
Reordered & commented eslint rule for ease of use
- These rules are currently off. We turn them on whilst testing atm to see progress.
- We will turn the core/server rule on sooner than the core/shared one.
- Commented the core/shared rule out and put it first so I don't have to keep adding/removing the comma
2021-10-16 16:30:46 +01:00
Hannah Wolfe
857a6975d0
Fixed incorrect eslint rule config 2021-09-30 14:59:01 +01:00
Hannah Wolfe
b98b190097
Updated restricted require eslint warnings [off]
- These rules are currently off, but we use them for measuring progress towards our refactoring goals
2021-09-29 11:14:22 +01:00
Hannah Wolfe
df51da5f7e
Updated eslint rules for plugin v2.4.0
refs: 10d02e8343
refs: 83a30775bf
refs: 3355f627c4
refs: 0e9b950558

- In eslint-plugin-ghost 2.4.0 I moved some of the rules implmented in Ghost as they are global rules, including:
   - no new Error()  - use @tryghost/errors
   - forcing index.js to be under 50 chars as a leading indicator for misuse of index files
- I also added new rules to check for tpl('literal string') and the deprecated ghost-ignition package
- Because the new Error and tpl rules are both implemented with no-restricted-syntax, the local rules overrode the global one
- Removing the rule here allows the global ones to work
- Have to think about how to do this long term
2021-06-30 15:51:48 +01:00
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