-
Notifications
You must be signed in to change notification settings - Fork 6
Support programmatic linting, remove FS-centric bundle management #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ca0e988
Refactoring processor en route to programmatic configuration
khawkins a38cc48
Refactoring to work with code as data structure, not simply fs-based
khawkins 4f9ce52
Cleaning up type declarations
khawkins 14623b2
Processor code cleanup
khawkins 632a0c2
Adding custom no-op parser
khawkins bb7391c
Taking __filename out of rule creation
khawkins 3069b0f
Moving LwcBundle to its own class/module
khawkins e1cdb24
Adding bundle cache manager
khawkins 69e05af
rest parameters for htmlTemplateContent, bug fix on sourceCode
khawkins 21862fc
Interface, test updates
khawkins fc7d050
Tweaking tests, validation logic
khawkins 88f3d0f
Updating package version
khawkins 7acb1a4
Fix Windows tests (paths)
khawkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import type { Linter, ESLint } from 'eslint'; | ||
|
||
/** | ||
* Represents a file in an LWC bundle, with its content and designation as the primary file, | ||
* i.e. the file requested by ESLint to be linted. | ||
*/ | ||
export type LwcBundleFile = { | ||
/** The name of the file */ | ||
filename: string; | ||
/** The content of the file */ | ||
content: string; | ||
/** Whether this is the primary file being linted by ESLint */ | ||
isPrimary: boolean; | ||
}; | ||
|
||
/** | ||
* Represents a bundle of files that make up an LWC component. The bundle contains the JavaScript | ||
* file and any HTML template files that comprise the component. One file in the bundle will be | ||
* designated as the primary file, which is the file that ESLint is currently processing. | ||
*/ | ||
declare class LwcBundle { | ||
/** | ||
* Creates a new LWC bundle instance | ||
* | ||
* @param componentBaseName - The base name of the component (e.g., 'myComponent' for 'myComponent.js' et al) | ||
* @param js - The JavaScript file of the bundle, if present | ||
* @param htmlTemplates - The HTML template files of the bundle, if present | ||
*/ | ||
constructor(componentBaseName: string, js?: LwcBundleFile, htmlTemplates?: LwcBundleFile[]); | ||
|
||
/** Gets the base name of the component */ | ||
get componentBaseName(): string; | ||
|
||
/** Gets the JavaScript file of the bundle, if present */ | ||
get js(): LwcBundleFile | undefined; | ||
|
||
/** Gets the HTML template files of the bundle, if present */ | ||
get htmlTemplates(): LwcBundleFile[] | undefined; | ||
|
||
/** Gets the primary file being linted by ESLint */ | ||
get primaryFile(): LwcBundleFile; | ||
|
||
/** | ||
* Creates a record of filenames to their content for Komaci analysis | ||
* | ||
* @returns A record mapping filenames to their content | ||
*/ | ||
filesRecord(): Record<string, string>; | ||
|
||
/** | ||
* Sets the primary file in the bundle based on content matching | ||
* | ||
* @param content - The content to match against | ||
* @returns True if a matching file was found and set as primary | ||
*/ | ||
setPrimaryFileByContent(content: string): boolean; | ||
|
||
/** | ||
* Creates an `LwcBundle` instance from the specified content files. The primary file | ||
* designation will be set later when the bundle is processed by ESLint. | ||
* | ||
* @param componentBaseName - The base name of the component | ||
* @param jsContent - The content of the JavaScript file, if present | ||
* @param htmlTemplateContent - The contents of the HTML template files, if any | ||
* @returns A new LWC bundle instance | ||
*/ | ||
static lwcBundleFromContent( | ||
componentBaseName: string, | ||
jsContent?: string, | ||
...htmlTemplateContent: string[] | ||
): LwcBundle; | ||
|
||
/** | ||
* Creates a bundle from filesystem files | ||
* | ||
* @param lwcFileContent - The content of the file being processed | ||
* @param lwcFilePath - The path to the file being processed | ||
* @param lwcFileExtension - The file extension of the file being processed | ||
* @returns A new LWC bundle instance, or null if the file cannot be found | ||
*/ | ||
static lwcBundleFromFilesystem( | ||
lwcFileContent: string, | ||
lwcFilePath: string, | ||
lwcFileExtension: string | ||
): LwcBundle | null; | ||
} | ||
|
||
/** | ||
* ESLint processor that analyzes LWC bundles. This will set up the LWC bundle to be processed | ||
* by Komaci. | ||
*/ | ||
export class BundleAnalyzer implements Linter.Processor { | ||
/** Gets the current LWC bundle being processed */ | ||
get lwcBundle(): LwcBundle | null; | ||
|
||
/** Sets the LWC bundle to be processed */ | ||
set lwcBundle(value: LwcBundle | null); | ||
|
||
/** | ||
* Sets the LWC bundle content from content files | ||
* | ||
* @param componentBaseName - The base name of the component | ||
* @param jsContent - The content of the JavaScript file, if present | ||
* @param htmlTemplateContent - The contents of the HTML template files, if any | ||
*/ | ||
setLwcBundleFromContent( | ||
componentBaseName: string, | ||
jsContent?: string, | ||
...htmlTemplateContent: string[] | ||
): void; | ||
|
||
/** | ||
* Preprocesses the input file for ESLint | ||
* | ||
* @param text - The content of the ESLint file | ||
* @param filename - The input filename | ||
* @returns An array of files and their content to be processed | ||
*/ | ||
preprocess(text: string, filename: string): string[]; | ||
|
||
/** | ||
* Postprocesses the linting results | ||
* | ||
* @param messages - The two-dimensional array of messages returned from linting | ||
* @param filename - The input filename | ||
* @returns A one-dimensional flattened array of messages | ||
*/ | ||
postprocess(messages: Linter.LintMessage[][], filename: string): Linter.LintMessage[]; | ||
|
||
/** Whether the processor supports autofix */ | ||
supportsAutofix: boolean; | ||
} | ||
|
||
/** | ||
* The ESLint plugin for LWC graph analysis | ||
*/ | ||
declare const lwcGraphAnalyzerPlugin: ESLint.Plugin & { | ||
/** The bundle analyzer processor */ | ||
processors: { | ||
bundleAnalyzer: BundleAnalyzer; | ||
}; | ||
/** The plugin's configuration presets */ | ||
configs: { | ||
base: Linter.Config; | ||
recommended: Linter.Config; | ||
}; | ||
}; | ||
|
||
export = lwcGraphAnalyzerPlugin; | ||
export { LwcBundle }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, every project that included our plugin also had to include one of the LWC ESLint configs from
eslint-config-lwc
, to get the parser that would accept LWC code with decorators.