Skip to content

[Proposal/Discussion/WIP] Use ESLint and Stylelint to check for potential errors and enforce a consistent coding style - #69

Draft
AnSq wants to merge 7 commits into
warframe-tools:mainfrom
AnSq:eslint
Draft

[Proposal/Discussion/WIP] Use ESLint and Stylelint to check for potential errors and enforce a consistent coding style#69
AnSq wants to merge 7 commits into
warframe-tools:mainfrom
AnSq:eslint

Conversation

@AnSq

@AnSq AnSq commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

AI Disclosure:

  • I did not use AI for anything in this pull request.
  • I did use AI in this pull request, and I have included a statement of AI use in the commit message of every commit where I used AI.

ESLint is a static code analysis tool that can catch common JavaScript problems and enforce a consistent coding style. I propose that we adopt it for this project. This PR contains my work so far in setting it up. It is currently a draft while I gather feedback, fine tune the rule settings, and integrate it into our workflow.

Proposed Coding Style

JavaScript

  • Indent with 4 spaces.
  • Require semicolons.
  • Use double quotes, unless single quotes would allow for fewer escape sequences.
  • Single-parameter arrow functions must always use parentheses.
  • Single-statement blocks must use braces.
  • Use the "one true brace style".
    • The exception to this is when an if and else block each have exactly one statement. Unfortunately, the eslint rule doesn't seem to support this. I could maybe write my own, but that seems like a bunch of extra work for not a lot of benefit. Just use /* eslint-disable-line @stylistic/brace-style */ for these cases.
  • Multiline arrays and object literals must have a trailing comma.
  • Curly braces must have spaces on their inner face (for blocks and objects, unless the object is empty).

There are many other rules active from the recommended configuration, but most of them are fairly obvious or have little-to-no effect on our codebase because we're already following them or don't use those language features.

CSS

  • Use the recommended CSS configuration with the following modifications:
    • Warn instead of erroring on !important. (None of our uses of !important seemed necessary, so I removed them all anyway.)
    • Warn instead of erroring on features that are not baseline widely available.
      • Some non-widely-available features are allowed if they've almost graduated from "newly" to "widely" available, or if their effect is small.

JSON

Integration

I plan to set up a GitHub Action to automatically run eslint on push and on pull request, much like we already have for vitest. I may also write a pre-commit hook to do it for you locally.

For now, once you have checked out this branch and run npm install, you can run npx eslint to run the checks. There's also an extension for VS Code and vscodium and compatible editors to highlight problems directly in your editor.

Comment thread sources/js/app.js
}

function createChecklistItem(task) {
function createChecklistItem(task) { /* eslint-disable-line complexity, max-lines-per-function */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of places where I've enabled a complexity rule (like complexity, max-lines-per-function, or max-depth) and then ignored all the violations. The rule is enabled so that the writer of the code is warned that the function they're writing might be getting out of hand and it might be time to refactor something. If that's deemed infeasible or not worth it though, then the eslint-disable comment warns the reader of the code of the potential difficulty in wrapping their brain around it, but assures them that the writer is at least aware of the issue.

Comment thread sources/js/app.js
Comment on lines +570 to 571
if (task.id.startsWith("daily_")) { when = "today"; } /* eslint-disable-line @stylistic/brace-style */
else if (task.id.startsWith("weekly_")) { when = "this week"; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of the trouble with brace-style

Comment thread sources/js/app.js
}

function updateIncompleteSubtaskCount(task, queryFrom=document) {
function updateIncompleteSubtaskCount(task, queryFrom = document) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer no spaces here, but @stylistic/space-infix-ops doesn't have an option for "ignore default parameters", and that's a sacrifice I'm willing to make.

Comment thread sources/css/style.css Outdated
Comment on lines +491 to +492
#more-info {
p:not(:last-child):not(:has(+ :is(ul, table))), table {
p:not(:last-child):not(:has(+ :is(ul, table))), table { /* eslint-disable-line css/no-invalid-properties -- eslint bug workaround */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint has trouble parsing some nested CSS

Comment thread sources/js/app.js

const now = new Date();
const taskTimes = calcTaskTimes(task, now);
const cycleNumber = calcCycleNumber(task, now);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, look at that! It already caught an error!

(I accidentally deleted the definition of cycleNumber in a previous commit.)

@HelpfulSoft1207

Copy link
Copy Markdown
Collaborator

I had not heard of ESLint before, I will check this out this weekend, but so far looks promising. I like the idea of having a consistent coding style for posterity.

@AnSq

AnSq commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

I added Stylelint for checking CSS. It has better support and more options for CSS than ESLint. Right now it's set up to use both ESLint and Stylelint on CSS files, which seems like maybe a bad idea, but they haven't seemed to clash too much so 🤷.

The biggest changes here are enforcing modern color function notation and percentages for alpha values.

The Stylelint config is also a work in progress.

Comment thread sources/css/style.css
Comment on lines 193 to -194
input[type="checkbox"] {
appearance: none; -webkit-appearance: none; -moz-appearance: none;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appearance: none is widely supported without a vendor prefix

@AnSq AnSq changed the title [Proposal/Discussion/WIP] Use ESLint to check for potential errors and enforce a consistent coding style [Proposal/Discussion/WIP] Use ESLint and Stylelint to check for potential errors and enforce a consistent coding style Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants