-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESLint plugin - initial refactor + reintroduce test of graph with a s…
…ubgraph (#141) * Move tests to a dedicated folder * Build obsidian before eslint plugin + fix tsconfig in eslint plugin * Move testUtils to tests folder + fix eslint warning in IDE * Properly exclude tests from dist * oopsie woopsie * Mock file path resolving in tests + reintroduce subgraph test
- Loading branch information
Showing
16 changed files
with
97 additions
and
48 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
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
8 changes: 8 additions & 0 deletions
8
packages/eslint-plugin-obsidian/rules/framework/pathResolver.ts
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 @@ | ||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'; | ||
import path = require('path') ; | ||
|
||
export class PathResolver { | ||
public resolve(context: RuleContext<any, any>, relativeFilePath: string) { | ||
return path.join(path.dirname(context.getFilename()), `${relativeFilePath}.ts`); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const { unresolvedProviderDependencies } = require('./unresolvedProviderDependencies'); | ||
const { unresolvedProviderDependenciesGenerator } = require('./unresolvedProviderDependencies'); | ||
|
||
module.exports = { | ||
rules: { | ||
'unresolved-provider-dependencies': unresolvedProviderDependencies, | ||
'unresolved-provider-dependencies': unresolvedProviderDependenciesGenerator(), | ||
}, | ||
}; |
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
43 changes: 25 additions & 18 deletions
43
packages/eslint-plugin-obsidian/rules/unresolvedProviderDependencies/index.ts
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 |
---|---|---|
@@ -1,26 +1,33 @@ | ||
import { ESLintUtils, type TSESLint } from '@typescript-eslint/utils'; | ||
import { create } from './createFunction'; | ||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'; | ||
import { create } from './createRule'; | ||
import { PathResolver } from '../framework/pathResolver'; | ||
|
||
type Rule = TSESLint.RuleModule<'unresolved-provider-dependencies', []>; | ||
|
||
const createRule = ESLintUtils.RuleCreator( | ||
(name) => `https://wix-incubator.github.io/obsidian/docs/documentation/meta/eslint#${name}`, | ||
); | ||
|
||
type Rule = TSESLint.RuleModule<'unresolved-provider-dependencies', []>; | ||
|
||
|
||
export const unresolvedProviderDependencies: Rule = createRule({ | ||
create, | ||
name: 'unresolved-provider-dependencies', | ||
meta: { | ||
docs: { | ||
description: 'Dependencies must be defined in the graph or its subgraphs.', | ||
recommended: 'strict', | ||
export const unresolvedProviderDependenciesGenerator = ( | ||
pathResolver: PathResolver = new PathResolver(), | ||
) => { | ||
return createRule({ | ||
create: (context: RuleContext<'unresolved-provider-dependencies', []>) => { | ||
return create(context, pathResolver); | ||
}, | ||
messages: { | ||
'unresolved-provider-dependencies': 'Dependency {{ dependencyName }} is unresolved.', | ||
name: 'unresolved-provider-dependencies', | ||
meta: { | ||
docs: { | ||
description: 'Dependencies must be defined in the graph or its subgraphs.', | ||
recommended: 'strict', | ||
}, | ||
messages: { | ||
'unresolved-provider-dependencies': 'Dependency {{ dependencyName }} is unresolved.', | ||
}, | ||
schema: [], | ||
type: 'problem', | ||
}, | ||
schema: [], | ||
type: 'problem', | ||
}, | ||
defaultOptions: [], | ||
}); | ||
defaultOptions: [], | ||
}) satisfies Rule; | ||
}; |
16 changes: 0 additions & 16 deletions
16
...slint-plugin-obsidian/rules/unresolvedProviderDependencies/unresolvedDependencies.test.ts
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
packages/eslint-plugin-obsidian/tests/stubs/PathResolverStub.ts
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,14 @@ | ||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'; | ||
import path = require('path') ; | ||
import { PathResolver } from '../../rules/framework/pathResolver'; | ||
|
||
export class PathResolverStub implements PathResolver { | ||
public resolve(context: RuleContext<any, any>, relativeFilePath: string): string { | ||
switch(relativeFilePath) { | ||
case './subgraph': | ||
return `${context.cwd}/tests/unresolvedProviderDependencies/testUtils/subgraph.ts`; | ||
default: | ||
return path.join(path.dirname(context.getFilename()), `${relativeFilePath}.ts`); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
...slint-plugin-obsidian/tests/unresolvedProviderDependencies/unresolvedDependencies.test.ts
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,23 @@ | ||
import { RuleTester } from '@typescript-eslint/rule-tester'; | ||
import { validGraphSimple, validGraphWithSubgraph } from './testUtils/validGraphs'; | ||
import { unresolvedProviderDependenciesGenerator } from '../../rules/unresolvedProviderDependencies'; | ||
import { invalidGraph } from '../../rules/unresolvedProviderDependencies/invalidGraphs'; | ||
import { PathResolverStub } from '../stubs/PathResolverStub'; | ||
|
||
const ruleTester = new RuleTester(); | ||
|
||
ruleTester.run( | ||
'unresolved-provider-dependencies', | ||
unresolvedProviderDependenciesGenerator(new PathResolverStub()), | ||
{ | ||
valid: [validGraphSimple, validGraphWithSubgraph], | ||
invalid: [ | ||
{ | ||
code: invalidGraph, | ||
errors: [{ | ||
messageId: 'unresolved-provider-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"include": [ | ||
"rules/**/*", | ||
"tests/**/*", | ||
".eslintrc.js", | ||
], | ||
"exclude": [ | ||
|
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,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [ | ||
"**/*.test.*", | ||
"tests" | ||
] | ||
} |
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