Skip to content

Add ESLint and Prettier to py-slang#88

Open
AaravMalani wants to merge 6 commits intomainfrom
add-eslint
Open

Add ESLint and Prettier to py-slang#88
AaravMalani wants to merge 6 commits intomainfrom
add-eslint

Conversation

@AaravMalani
Copy link

@AaravMalani AaravMalani commented Mar 6, 2026

Solves issue #84
There are some manual type changes and TODOs left for types who I've not yet moved from any, such as moving Value back to a union of NumberValue, StringValue, etc.

@AaravMalani AaravMalani marked this pull request as ready for review March 7, 2026 12:42
@AaravMalani
Copy link
Author

Everything's set for review, but should we include src/tests in ESLint?
ESLint doesn't accept it since it's excluded in the tsconfig.json, and Rollup fails if it builds the files in src/tests. If I could disable src/tests in Rollup, I'd be able to reinclude src/tests in tsconfig.json so I could test with ESLint, but I can't figure out how to disable it

...
typescript({ exclude: ["src/tests/**/*.ts"] })
// and
typescript({ exclude: ["src/tests"] })
// and
typescript({ exclude: ["src/tests/*.ts"] })
...

None of the above options worked for me, please let me know if there's a way to do it I'm not thinking of

package.json Outdated
Comment on lines +15 to +16
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
"format:ci": "prettier --list-different \"src/**/*.{ts,tsx}\"",
Copy link
Member

Choose a reason for hiding this comment

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

Let's format . instead of src to include package.json, eslint config etc. (which is currently improperly formatted)

Add a .prettierignore file so it excludes the docs folder.

tseslint.configs.recommended,
eslintConfigPrettierFlat,
{
files: ['**/*.ts*'],
Copy link
Member

Choose a reason for hiding this comment

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

scope to src/**/*.{ts,tsx}, this scans way too many files

Copy link
Author

Choose a reason for hiding this comment

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

I disagree, since it runs on src in the command anyways, but I agree if anyone runs it without npm run lint, it would be painful

tsconfig.json Outdated
"rollup.config.js",
"src/tests",
"rollup.config.js"
".prettierrc",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't need this, it's not a JS/TS file

Copy link
Author

Choose a reason for hiding this comment

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

Ah, sorry about that
I forgot to remove them when I was done testing for the src/tests bug I'm encountering

tsconfig.json Outdated
"src/tests",
"rollup.config.js"
".prettierrc",
"eslint.config.mjs"
Copy link
Member

Choose a reason for hiding this comment

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

Why are we excluding it?

Copy link
Author

Choose a reason for hiding this comment

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

Oh I remember why, it's because Typescript threatened to overwrite them for some reason
I think it makes sense to just restrict Typescript to src, since no other Typescript files are present anywhere else in py-slang

tsconfig.json Outdated
"jest.config.js",
"node_modules",
"dist",
"rollup.config.js",
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, why are we excluding it?

}
},
{
files: ['**/*.js'],
Copy link
Member

Choose a reason for hiding this comment

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

Again, this is too huge. This also gives a subtle problem with code fragility because you are running tseslint on files like ESLint and Rollup config, but without the project service, so not all rules may be applicable (aka it just "happens to" work for this case, not "guaranteed" to work for all cases).

Copy link
Author

Choose a reason for hiding this comment

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

I've restricted it to src/**/*.js (although for now, that's not gonna be used for a while) for now
Isn't the project service a typescript-eslint feature IIRC?
Hope this solves the issue, though!

package.json Outdated
Comment on lines +58 to +60
"eslint": "^9.39.3",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-import": "^2.32.0",
Copy link
Member

Choose a reason for hiding this comment

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

Lint and format, etc, should all be devDependencies, not dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

Huh, I thought I used -D
Thanks for pointing it out!

@RichDom2185
Copy link
Member

Everything's set for review, but should we include src/tests in ESLint? ESLint doesn't accept it since it's excluded in the tsconfig.json, and Rollup fails if it builds the files in src/tests. If I could disable src/tests in Rollup, I'd be able to reinclude src/tests in tsconfig.json so I could test with ESLint, but I can't figure out how to disable it

...
typescript({ exclude: ["src/tests/**/*.ts"] })
// and
typescript({ exclude: ["src/tests"] })
// and
typescript({ exclude: ["src/tests/*.ts"] })
...

None of the above options worked for me, please let me know if there's a way to do it I'm not thinking of

Sorry, what do you mean?

  • ESLint doesn't accept it since it's excluded in the tsconfig.json

    ESLint should ideally lint test files too (may or may not use a different ruleset compared to source files); why would it not accept it just because it's excluded in tsconfig.json? ESLint and tsconfig.json are two separate things

  • Rollup fails if it builds the files in src/tests

    Yeah makes sense, Rollup shouldn't build tests in the first place.

  • I'd be able to reinclude src/tests in tsconfig.json so I could test with ESLint

    You don't have to include src/tests in tsconfig.json to lint it with ESLint. They are two completely separate things

  • but I can't figure out how to disable it

    Disable what?

@AaravMalani
Copy link
Author

ESLint should ideally lint test files too (may or may not use a different ruleset compared to source files); why would it not accept it just because it's excluded in tsconfig.json? ESLint and tsconfig.json are two separate things

No, they aren't because typescript-eslint accepts tsconfig.json to know the project in parserOptions, so it also accepts the exclusion list

...
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        project: './tsconfig.json',
      },
    },
...

If I include the tests, it errors out with

/root/source-academy/py-slang/src/tests/wasm-compiler.spec.ts
  0:0  error  Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): src/tests/wasm-compiler.spec.ts

Disable what?

The inclusion of src/tests in the Rollup build, sorry I wasn't clear
Although now that I think about it, maybe creating a separate tsconfig.eslint.json which extends from tsconfig.json but includes the tests could work, I'll have to test that

…t not working on tests + Move linter + formatters to `devDependencies`
@AaravMalani
Copy link
Author

AaravMalani commented Mar 8, 2026

ESLint should ideally lint test files too (may or may not use a different ruleset compared to source files); why would it not accept it just because it's excluded in tsconfig.json? ESLint and tsconfig.json are two separate things

No, they aren't because typescript-eslint accepts tsconfig.json to know the project in parserOptions, so it also accepts the exclusion list

...
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        project: './tsconfig.json',
      },
    },
...

If I include the tests, it errors out with

/root/source-academy/py-slang/src/tests/wasm-compiler.spec.ts
  0:0  error  Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): src/tests/wasm-compiler.spec.ts

Disable what?

The inclusion of src/tests in the Rollup build, sorry I wasn't clear Although now that I think about it, maybe creating a separate tsconfig.eslint.json which extends from tsconfig.json but includes the tests could work, I'll have to test that

Nevermind, I think projectService.allowDefaultProject was what I was looking for
Thanks for your help, though!

@martin-henz martin-henz requested a review from mug1wara26 March 9, 2026 01:00
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