-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add plugin for xo config (#621)
* feat(plugins): add plugin for xo config Adds a plugin for [xo](https://github.com/xojs/xo#config). Essentially its an opinionated wrapper around eslint with a bunch of bundled rules and plugins, and the config object is just the eslint config object with some extra options. So to keep it consistent with the eslint plugin and avoid duplication I've just used the eslint helper to parse out any additional eslint plugins that have been added in the xo config. * Add xo bin --------- Co-authored-by: Lars Kappert <[email protected]>
- Loading branch information
Showing
11 changed files
with
113 additions
and
0 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,9 @@ | ||
module.exports = { | ||
space: true, | ||
prettier: true, | ||
plugins: ['unused-imports'], | ||
parserOptions: {emitDecoratorMetadata: true}, | ||
rules: { | ||
'func-names': ['error', 'always'], | ||
}, | ||
}; |
Empty file.
4 changes: 4 additions & 0 deletions
4
packages/knip/fixtures/plugins/xo/node_modules/xo/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@fixtures/xo", | ||
"scripts": { | ||
"test": "xo" | ||
}, | ||
"devDependencies": { | ||
"xo": "^0.24.0" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"plugins": ["eslint-comments"] | ||
} | ||
} |
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,8 @@ | ||
const mySharedConfig = require('glob'); | ||
|
||
module.exports = { | ||
...mySharedConfig, | ||
rules: { | ||
'func-names': 'off', | ||
}, | ||
}; |
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,34 @@ | ||
import type { EnablerPatterns } from '#p/types/config.js'; | ||
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js'; | ||
import { hasDependency } from '#p/util/plugin.js'; | ||
import { getDependenciesDeep } from '../eslint/helpers.js'; | ||
import type { XOConfig } from './types.js'; | ||
|
||
// link to xo docs: https://github.com/xojs/xo#config | ||
|
||
const title = 'xo'; | ||
|
||
const enablers: EnablerPatterns = ['xo']; | ||
|
||
const isEnabled: IsPluginEnabled = ({ dependencies, config }) => | ||
hasDependency(dependencies, enablers) || 'xo' in config; | ||
|
||
const packageJsonPath = 'xo'; | ||
const config: string[] = ['{.,}xo-config.{js,cjs,json,}', 'package.json']; | ||
|
||
const entry: string[] = ['{.,}xo-config.{js,cjs}']; | ||
|
||
const resolveConfig: ResolveConfig<XOConfig> = async (config, options) => { | ||
const dependencies = await getDependenciesDeep(config, options); | ||
return [...dependencies]; | ||
}; | ||
|
||
export default { | ||
title, | ||
enablers, | ||
isEnabled, | ||
packageJsonPath, | ||
entry, | ||
config, | ||
resolveConfig, | ||
} satisfies Plugin; |
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,13 @@ | ||
import type { ESLintConfig } from '../eslint/types.js'; | ||
|
||
export type XOConfig = ESLintConfig & { | ||
envs?: string[] | undefined; | ||
globals?: string[] | undefined; | ||
ignores?: string[] | undefined; | ||
nodeVersion?: string | boolean | undefined; | ||
prettier?: boolean | undefined; | ||
printConfig?: string | undefined; | ||
semicolon?: boolean | undefined; | ||
space?: boolean | number | undefined; | ||
webpack?: boolean | object | undefined; | ||
}; |
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,26 @@ | ||
import { test } from 'bun:test'; | ||
import assert from 'node:assert/strict'; | ||
import { main } from '../../src/index.js'; | ||
import { resolve } from '../../src/util/path.js'; | ||
import baseArguments from '../helpers/baseArguments.js'; | ||
import baseCounters from '../helpers/baseCounters.js'; | ||
|
||
const cwd = resolve('fixtures/plugins/xo'); | ||
|
||
test('Find dependencies with the xo plugin', async () => { | ||
const { issues, counters } = await main({ | ||
...baseArguments, | ||
cwd, | ||
}); | ||
|
||
assert(issues.unlisted['.xo-config.js']['eslint-plugin-unused-imports']); | ||
assert(issues.unlisted['xo-config.cjs']['glob']); | ||
assert(issues.unlisted['package.json']['eslint-plugin-eslint-comments']); | ||
|
||
assert.deepEqual(counters, { | ||
...baseCounters, | ||
processed: 2, | ||
unlisted: 3, | ||
total: 2, | ||
}); | ||
}); |