-
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-config)!: add a config preset for validating dependencies…
… in package.json files (#813)
- Loading branch information
1 parent
d673453
commit 167311e
Showing
12 changed files
with
547 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@bfra.me/eslint-config": minor | ||
--- | ||
|
||
Add a config preset for validating dependencies in package.json files. | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,43 @@ | ||
import type {Config} from '../config' | ||
import type {Flatten, OptionsFiles} from '../options' | ||
import {anyParser} from '../parsers/any-parser' | ||
import {interopDefault} from '../plugins' | ||
import {requireOf} from '../require-of' | ||
import {fallback} from './fallback' | ||
import {jsonSchema} from './json-schema' | ||
|
||
export type PackageJsonOptions = Flatten<OptionsFiles> | ||
|
||
export const packageJsonFiles = ['package.json', 'package.json5', 'package.jsonc'].flatMap(file => [ | ||
file, | ||
`**/${file}`, | ||
]) | ||
|
||
export async function packageJson(options: PackageJsonOptions = {}): Promise<Config[]> { | ||
const {files = packageJsonFiles} = options | ||
return requireOf( | ||
['eslint-plugin-node-dependencies'], | ||
async () => { | ||
// @ts-expect-error: Missing type definitions | ||
const pluginNodeDependencies = await interopDefault(import('eslint-plugin-node-dependencies')) | ||
return [ | ||
...pluginNodeDependencies.configs['flat/recommended'].map( | ||
(config: Config, index: number) => ({ | ||
...config, | ||
name: config.plugins | ||
? `@bfra.me/package-json/plugins` | ||
: `@bfra.me/${config.name || `package-json/unnamed${index}`}`, | ||
files, | ||
}), | ||
), | ||
...(await jsonSchema('package-json', files as string[])), | ||
] | ||
}, | ||
async missingList => | ||
fallback(missingList, { | ||
name: '@bfra.me/package-json/fallback', | ||
files, | ||
languageOptions: {parser: anyParser}, | ||
}), | ||
) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.