11import eslint from '@eslint/js'
2+ import { defineConfig as packageConstraints , getNpmWorkspaceJSON } from '@kumahq/eslint-package-constraints'
23import stylistic from '@stylistic/eslint-plugin'
34import { defineConfigWithVueTs , vueTsConfigs } from '@vue/eslint-config-typescript'
4- import escape from 'escape-string-regexp'
55import importPlugin from 'eslint-plugin-import'
6- import jsonSchemaValidatorPlugin from 'eslint-plugin-json-schema-validator'
76import nounsanitized from 'eslint-plugin-no-unsanitized'
87import vuePlugin from 'eslint-plugin-vue'
98import globals from 'globals'
10- import { execSync } from 'node:child_process'
11- import { readFileSync as read } from 'node:fs'
12- import { resolve , dirname } from 'node:path'
13- import { fileURLToPath } from 'node:url'
14-
15- const $config = dirname ( fileURLToPath ( import . meta. resolve ( '@kumahq/config' ) ) )
16-
17- const workspace = JSON . parse (
18- execSync ( 'npm query :root' ) . toString ( ) ,
19- ) . at ( 0 )
20-
21- const packageSchema = JSON . parse (
22- read ( resolve ( `${ $config } /package.schema.json` ) , 'utf-8' ) ,
23- )
24-
25- const workflowSchema = JSON . parse (
26- read ( resolve ( `${ $config } /workflow.schema.json` ) , 'utf-8' ) ,
27- )
289
2910// Taken from https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/utils/inline-non-void-elements.json.
3011const INLINE_NON_VOID_ELEMENTS = [
@@ -76,39 +57,16 @@ export function createEslintConfig(
7657 {
7758 tsConfigPath = 'tsconfig.json' ,
7859 componentIgnorePatterns = [ ] ,
79- versionIgnorePatterns = { } ,
60+ dependencyIgnorePatterns = { } ,
8061 workspaceRoot = false ,
8162 } = {
8263 tsConfigPath : 'tsconfig.json' ,
8364 componentIgnorePatterns : [ ] ,
84- versionIgnorePatterns : { } ,
65+ dependencyIgnorePatterns : { } ,
8566 workspaceRoot : false ,
8667 } ,
8768) {
8869
89- // amend our package.json schema depending on arguments
90- ( ( schema ) => {
91- // 1. include any ignored version patterns
92- [ 'dependencies' , 'devDependencies' , 'peerDependencies' ] . forEach ( ( item ) => {
93- schema . properties [ item ] . patternProperties = {
94- ...schema . properties [ item ] . patternProperties ,
95- ...versionIgnorePatterns [ item ] ?? { } ,
96- }
97- } )
98-
99- // 2. Take engines from the root of kumahq/kuma-gui and make sure
100- // any other workspace root using this linter use the same engines
101- Object . entries ( workspace . engines ) . forEach ( ( [ key , value ] ) => {
102- schema . definitions [ key ] . pattern = `^${ escape ( value ) } $`
103- } )
104-
105- // 3. Any non-root package.json files shouldn't ever specify `engines`
106- if ( ! workspaceRoot ) {
107- schema . properties . engines = {
108- not : { } ,
109- }
110- }
111- } ) ( packageSchema )
11270
11371 const vueTsConfig = defineConfigWithVueTs (
11472 ...vuePlugin . configs [ 'flat/recommended' ] ,
@@ -124,30 +82,6 @@ export function createEslintConfig(
12482 } ,
12583 ]
12684
127- const jsonSchemaValidatorConfig = [
128- ...jsonSchemaValidatorPlugin . configs [ 'flat/recommended' ] ,
129- {
130- rules : {
131- 'json-schema-validator/no-invalid' : [ 'error' , {
132- useSchemastoreCatalog : false ,
133- mergeSchemas : true ,
134- schemas : [
135- {
136- fileMatch : [ 'package.json' ] ,
137- // our schema allows for ignoring individual dependencies if required
138- // see ./package.schema.json patternProperties examples
139- schema : packageSchema ,
140- } ,
141- {
142- fileMatch : [ '.github/**/*.{yaml,yml}' ] ,
143- schema : workflowSchema ,
144- } ,
145- ] ,
146- } ] ,
147- } ,
148- } ,
149- ]
150-
15185 const stylisticConfig = {
15286 plugins : {
15387 '@stylistic' : stylistic ,
@@ -181,19 +115,24 @@ export function createEslintConfig(
181115 '@stylistic/semi' : [ 'error' , 'never' ] ,
182116 } ,
183117 }
184-
118+ const workspaceJSON = getNpmWorkspaceJSON ( )
185119 return [
186120 // when linting workspaceRoots we want to ignore
187121 // sub-packages which are linted separately
188122 workspaceRoot ? {
189- ignores : workspace . workspaces ,
123+ ignores : workspaceJSON . workspaces ,
190124 } : { } ,
191- //
192125 eslint . configs . recommended ,
193126 nounsanitized . configs . recommended ,
194127 ...vueTsConfig ,
195128 ...importConfig ,
196- ...jsonSchemaValidatorConfig ,
129+ //
130+ ...packageConstraints ( {
131+ workspaceRoot,
132+ dependencyIgnorePatterns,
133+ workspaceJSON,
134+ } ) ,
135+ //
197136 stylisticConfig ,
198137 {
199138 languageOptions : {
0 commit comments