Open mmkal opened 1 year ago
IMHO, a better solution would be to use a library that lets you write it using a fluent and human-friendly API which then gets compiled down to a cron expression. Basically, the inverse.
Also, a problem with a comment like that is that it's easy for it to get outdated.
Also, a problem with a comment like that is that it's easy for it to get outdated.
The lint rule would make sure the comment stayed up to date and accurate. It'd be a lint error if the cron expression changed without updating the comment.
the inverse
Agreed about a fluent api being ideal, but realistically there will still be cron expressions used, especially in places where it's not practical to add such a library as a dependency for whatever reason. The nice thing about a lint rule is it's only a dev dependency.
The YAML use case is the clearest one to see - cron expressions are used in GitHub actions yaml, as well kubernetes resource files, and lots of other declarative orchestration configs. Those can't use js libraries, but they can use eslint with an appropriate processor.
Description
Cron expressions are used in lots of places, but they're hard to read and misunderstanding them can be quite problematic.
This lint rule could detect cron expressions, and require the line above have a comment describing the expression accurately
Fail
Pass
Additional Info
The library construe can parse these expressions and produce a human-readable equivalent. Violations could be auto-fixable.
If it could support yaml as well, it'd work with github actions workflows etc.