Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Language Plugins #16999

Open
30 of 39 tasks
nzakas opened this issue Mar 16, 2023 · 13 comments
Open
30 of 39 tasks

Implement Language Plugins #16999

nzakas opened this issue Mar 16, 2023 · 13 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features

Comments

@nzakas
Copy link
Member

nzakas commented Mar 16, 2023

This issue describes the implementation plan for eslint/rfcs#99, which will take place in several phases:

Phase 1: Implement external changes

Phase 2: Implement backward-compatible changes

Phase 4: Deprecation of old APIs (v8.0.0)

  • Update RuleTester to warn about context.getAncestors()
  • Update RuleTester to warn about context.getDeclaredVariables()
  • Update RuleTester to warn about context.getScope()
  • Update RuleTester to warn about context.parserServices
  • Update RuleTester to warn about context.getCwd()
  • Update RuleTester to warn about context.getSourceCode()
  • Update RuleTester to warn about context.getFilename()
  • Update RuleTester to warn about context.getPhysicalFilename()

Phase 5: Removal of old APIs (v9.0.0)

  • Remove context.getAncestors()
  • Remove context.getDeclaredVariables()
  • Remove context.getScope()
  • Remove context.markVariableAsUsed()
  • Remove context.parserServices

Phase 6: Create JS language object

  • Create JS language object with parse() and createSourceCode()
  • Update flat config to have language option (also update default config to use JS language object)
  • Update Linter to call language object for parsing (fallback to JS language for eslintrc)
  • Update Linter to use SourceCode#getInlineConfig()
  • Update Linter to use SourceCode#getDisableDirectives()
  • Update Linter to use SourceCode#traverse()

Phase 7: Create @eslint/json package

TBD

Phase 8: Create @eslint/markdown package

TBD

Phase 9: Removal of old APIs (v10.0.0)

  • Remove context.getCwd()
  • Remove context.getSourceCode()
  • Remove context.getFilename()
  • Remove context.getPhysicalFilename()
@nzakas nzakas added core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible labels Mar 16, 2023
@nzakas nzakas self-assigned this Mar 16, 2023
nzakas added a commit that referenced this issue Mar 21, 2023
mdjermanovic pushed a commit that referenced this issue Mar 24, 2023
* feat: Copy getScope() to SourceCode

Refs #16999

* Fix no-obj-calls

* Add getScope() tests

* Throw error if argument is missing

* Update docs

* Add caching

* Clean up caching
mdjermanovic added a commit that referenced this issue Apr 7, 2023
* feat: Move getDeclaredVariables and getAncestors to SourceCode

Refs #16999

* Update rules to use sourceCode.getAncestors()

* Add caching to sourceCode.getAncestors()

* Update docs

* Fix getAncestors caching

* Update tests/lib/source-code/source-code.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update tests/lib/source-code/source-code.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update tests/lib/source-code/source-code.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Restore deprecated custom rules docs

* Update comments in source-code.js

* Check for missing argument in getAncestors()

* Check for missing argument in getAncestors()

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@snitin315
Copy link
Contributor

I can also help with phase 2, I can start with Copy context.markVariableAsUsed() to SourceCode. @nzakas Let me know if that's ok.

nzakas added a commit to eslint/eslint-scope that referenced this issue Apr 11, 2023
Renames the private __isNodejsScope to isGlobalReturn to formally make
it part of the interface and available in ESLint.

Refs eslint/eslint#16999
@nzakas
Copy link
Member Author

nzakas commented Apr 11, 2023

@snitin315 markVariableAsUsed() is a bit complicated, so I'd prefer to keep that one. If you could do the next few items (cwd, sourceCode, filename, and physicalFilename) that would be a huge help.

@amareshsm
Copy link
Member

@nzakas I can also help with some items (any of CWD, sourceCode, filename, and physicalFilename) if possible. Can you pls give some context?

@nzakas
Copy link
Member Author

nzakas commented Apr 12, 2023

@amareshsm if you'd like to take a look at those four, this is the part of the code involved:

eslint/lib/linter/linter.js

Lines 979 to 1000 in 9d1b8fc

const sharedTraversalContext = Object.freeze(
Object.assign(
Object.create(BASE_TRAVERSAL_CONTEXT),
{
getAncestors: () => sourceCode.getAncestors(currentNode),
getDeclaredVariables: node => sourceCode.getDeclaredVariables(node),
getCwd: () => cwd,
getFilename: () => filename,
getPhysicalFilename: () => physicalFilename || filename,
getScope: () => sourceCode.getScope(currentNode),
getSourceCode: () => sourceCode,
markVariableAsUsed: name => markVariableAsUsed(sourceCode, currentNode, languageOptions, name),
parserOptions: {
...languageOptions.parserOptions
},
parserPath: parserName,
languageOptions,
parserServices: sourceCode.parserServices,
settings
}
)
);

Basically, we want to create properties where there are currently methods, and then update all of the rules to use the properties instead of the methods.

mdjermanovic pushed a commit to eslint/eslint-scope that referenced this issue Apr 12, 2023
Renames the private __isNodejsScope to isGlobalReturn to formally make
it part of the interface and available in ESLint.

Refs eslint/eslint#16999
nzakas added a commit that referenced this issue Apr 13, 2023
Implements `SourceCode#markVariableAsUsed()` while leaving
`context.markVariableAsUsed()` alone.

Refs #16999
@ollie-iterators
Copy link

Phase 1 is finished!!!

nzakas added a commit that referenced this issue Apr 20, 2023
Implements `SourceCode#markVariableAsUsed()` while leaving
`context.markVariableAsUsed()` alone.

Refs #16999
mdjermanovic added a commit that referenced this issue Apr 20, 2023
* feat: Implement `SourceCode#markVariableAsUsed()`

Implements `SourceCode#markVariableAsUsed()` while leaving
`context.markVariableAsUsed()` alone.

Refs #16999

* Refactor markVariableAsUsed

* Finish refactor

* Update docs/src/extend/custom-rules.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update docs/src/extend/custom-rules.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update docs/src/extend/custom-rules.md

* Update logic to eliminate scopeManager dependency

* Update docs/src/extend/custom-rules.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Fix lint errors

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@ollie-iterators
Copy link

With #17086 merged, Copy context.markVariableAsUsed() to SourceCode should be checked off

@mdjermanovic
Copy link
Member

I'll work on parserServices.

@ollie-iterators
Copy link

With #17107 merged, Create context.sourceCode to replace context.getSourceCode() should be checked off

@nzakas
Copy link
Member Author

nzakas commented May 3, 2023

@ollie-iterators it seems like you enjoy tracking our tasks, do you have any interest in becoming more involved with the project?

@nzakas
Copy link
Member Author

nzakas commented May 3, 2023

I'm working on getInlineConfig next.

Edit: Okay, this is a lot more complicated than I realized initially. This may take a while and require some design changes.

@ollie-iterators
Copy link

@ollie-iterators it seems like you enjoy tracking our tasks, do you have any interest in becoming more involved with the project?

I haven't thought about that. I might be interested in that.

@nzakas
Copy link
Member Author

nzakas commented May 10, 2023

@ollie-iterators cool. If you want to discuss, swing by Discord and we'd be happy to chat.

@mdjermanovic
Copy link
Member

  • Copy parserServices to SourceCode

I'm working on this now.

parserServices actually already exists on SourceCode, so the task is only to update documentation and tests.

mdjermanovic added a commit that referenced this issue Jun 26, 2023
Deprecates `context.parserServices` in favor of `SourceCode#parserServices`

Refs #16999
nzakas pushed a commit that referenced this issue Jun 28, 2023
Deprecates `context.parserServices` in favor of `SourceCode#parserServices`

Refs #16999
nzakas added a commit that referenced this issue Aug 3, 2023
@nzakas nzakas added the tsc agenda This issue will be discussed by ESLint's TSC at the next meeting label Mar 1, 2024
nzakas added a commit that referenced this issue Mar 4, 2024
@nzakas nzakas removed the tsc agenda This issue will be discussed by ESLint's TSC at the next meeting label Mar 4, 2024
mdjermanovic pushed a commit that referenced this issue Mar 21, 2024
* feat: Implement SourceCode#traverse()

Refs #16999

* Add more debugging

* Clean up sourcecode

* Try to fix code paths

* Fix rules and update migration guide

* Cache traversal steps

* Fix lint error

* Fix fuzz test

* Simplify TraversalStep constructor

* Remove unused parent arg

* Fix constructor-super
nzakas added a commit that referenced this issue Apr 11, 2024
nzakas added a commit that referenced this issue Apr 12, 2024
mdjermanovic added a commit that referenced this issue Apr 17, 2024
* feat: Move directive gathering to SourceCode

refs #16999

* Add caching

* Update lib/linter/apply-disable-directives.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

---------

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features
Projects
Status: Implementing
Status: Done
Development

No branches or pull requests

5 participants