forked from AmadeusITGroup/otter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-plugin): yarnrc version harmonize
- Loading branch information
Showing
17 changed files
with
537 additions
and
268 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ generated-doc/ | |
/.vscode | ||
/tools/github-actions/*/packaged-action/ | ||
/**/src/**/package.json | ||
!/.yarnrc.yml |
This file contains 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 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 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 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
103 changes: 103 additions & 0 deletions
103
docs/linter/eslint-plugin/rules/yarnrc-package-extensions-harmonize.md
This file contains 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,103 @@ | ||
# Verify that the yarn package extensions versions | ||
|
||
This rule checks the `.yarnrc.yml` file to ensure that each version defined in the `packageExtensions` are aligned with the one used in the `package.json` files of the project. | ||
|
||
## Prerequisite | ||
|
||
The linter is dedicated to YAML files and requires the setup of the [yaml-eslint-parser](https://www.npmjs.com/package/yaml-eslint-parser). | ||
|
||
Example of a ESLint configuration: | ||
|
||
```json | ||
{ | ||
"parser": "yaml-eslint-parser", | ||
"plugins": [ | ||
"@o3r" | ||
], | ||
|
||
"files": [ | ||
"**/.yarnrc.yml" | ||
], | ||
"extends": [ | ||
"@o3r:yarn-recommended" | ||
] | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
### dependencyTypesInPackages | ||
|
||
List of dependency types to check in the package.json | ||
|
||
**Default**: ['optionalDependencies', 'dependencies', 'devDependencies', 'peerDependencies', 'generatorDependencies']* | ||
|
||
**Usage**: | ||
|
||
```json | ||
{ | ||
"@o3r/yarnrc-package-extensions-harmonize": [ | ||
"error", | ||
{ | ||
"dependencyTypesInPackages": ["dependencies", "peerDependencies"] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### ignoredDependencies | ||
|
||
List of dependencies to ignore. | ||
|
||
**Default**: *[]* | ||
|
||
**Usage**: | ||
|
||
```json | ||
{ | ||
"@o3r/yarnrc-package-extensions-harmonize": [ | ||
"error", | ||
{ | ||
"ignoredDependencies": ["rxjs", "@angular/*"] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### excludePackages | ||
|
||
List of package name to ignore when determining the dependencies versions. | ||
|
||
**Default**: *[]* | ||
|
||
**Usage**: | ||
|
||
```json | ||
{ | ||
"@o3r/yarnrc-package-extensions-harmonize": [ | ||
"error", | ||
{ | ||
"excludePackages": ["@o3r/core"] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### yarnrcDependencyTypes | ||
|
||
List of package extension types to check in the yarnrc. | ||
|
||
**Default**: *['peerDependencies', 'dependencies']* | ||
|
||
**Usage**: | ||
|
||
```json | ||
{ | ||
"@o3r/yarnrc-package-extensions-harmonize": [ | ||
"error", | ||
{ | ||
"yarnrcDependencyTypes": ["dependencies"] | ||
} | ||
] | ||
} | ||
``` |
This file contains 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 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 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 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 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 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,49 @@ | ||
import { ParserServices, TSESLint } from '@typescript-eslint/experimental-utils'; | ||
|
||
/** Basic interface for the Parser Services object provided by yaml-eslint-parser */ | ||
interface YamlParserServices extends ParserServices { | ||
isYAML: boolean; | ||
} | ||
|
||
/** | ||
* Determine if yaml-eslint-parser is used | ||
* @param parserServices Parser services object | ||
*/ | ||
export function isYamlParserServices(parserServices: any): parserServices is YamlParserServices { | ||
return !!parserServices && parserServices.isYAML; | ||
} | ||
|
||
/** | ||
* Retrieve the yaml parser services object or throw if the invalid parser is used | ||
* @param context Rule context | ||
*/ | ||
export function getYamlParserServices(context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>) { | ||
const parserService = context.parserServices; | ||
if (!isYamlParserServices(parserService)) { | ||
/* | ||
* The user needs to have configured "parser" in their eslint config and set it | ||
* to yaml-eslint-parser | ||
*/ | ||
throw new Error( | ||
'You have used a rule which requires \'yaml-eslint-parser\' to be used as the \'parser\' in your ESLint config.' | ||
); | ||
} | ||
return parserService; | ||
} | ||
|
||
/** | ||
* Utility for rule authors to ensure that their rule is correctly being used with yaml-eslint-parser | ||
* If yaml-eslint-parser is not the configured parser when the function is invoked it will throw | ||
* @param context | ||
*/ | ||
export function ensureJsoncParser(context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>): void { | ||
if (!(context.parserServices)) { | ||
/* | ||
* The user needs to have configured "parser" in their eslint config and set it | ||
* to yaml-eslint-parser | ||
*/ | ||
throw new Error( | ||
'You have used a rule which requires \'yaml-eslint-parser\' to be used as the \'parser\' in your ESLint config.' | ||
); | ||
} | ||
} |
Oops, something went wrong.