Skip to content

Commit

Permalink
refactor: exports json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 committed Jan 4, 2025
1 parent 9cce535 commit 93a62e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 56 deletions.
36 changes: 2 additions & 34 deletions rules/sort-intersection-types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import type { Options as SortUnionTypesOptions } from './sort-union-types'

import {
partitionByCommentJsonSchema,
partitionByNewLineJsonSchema,
specialCharactersJsonSchema,
newlinesBetweenJsonSchema,
ignoreCaseJsonSchema,
buildTypeJsonSchema,
alphabetJsonSchema,
localesJsonSchema,
groupsJsonSchema,
orderJsonSchema,
} from '../utils/common-json-schemas'
import { sortUnionOrIntersectionTypes } from './sort-union-types'
import { createEslintRule } from '../utils/create-eslint-rule'
import { jsonSchema } from './sort-union-types'

type MESSAGE_ID =
| 'missedSpacingBetweenIntersectionTypes'
Expand All @@ -38,28 +27,6 @@ let defaultOptions: Required<Options[0]> = {

export default createEslintRule<Options, MESSAGE_ID>({
meta: {
schema: [
{
properties: {
partitionByComment: {
...partitionByCommentJsonSchema,
description:
'Allows you to use comments to separate the intersection types members into logical groups.',
},
partitionByNewLine: partitionByNewLineJsonSchema,
specialCharacters: specialCharactersJsonSchema,
newlinesBetween: newlinesBetweenJsonSchema,
ignoreCase: ignoreCaseJsonSchema,
alphabet: alphabetJsonSchema,
type: buildTypeJsonSchema(),
locales: localesJsonSchema,
groups: groupsJsonSchema,
order: orderJsonSchema,
},
additionalProperties: false,
type: 'object',
},
],
messages: {
unexpectedIntersectionTypesGroupOrder:
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
Expand All @@ -75,6 +42,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
description: 'Enforce sorted intersection types.',
recommended: true,
},
schema: [jsonSchema],
type: 'suggestion',
fixable: 'code',
},
Expand Down
45 changes: 23 additions & 22 deletions rules/sort-union-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint'
import type { TSESTree } from '@typescript-eslint/types'

Expand Down Expand Up @@ -98,30 +99,29 @@ let defaultOptions: Required<Options[0]> = {
groups: [],
}

export let jsonSchema: JSONSchema4 = {
properties: {
partitionByComment: {
...partitionByCommentJsonSchema,
description:
'Allows you to use comments to separate the union types into logical groups.',
},
partitionByNewLine: partitionByNewLineJsonSchema,
specialCharacters: specialCharactersJsonSchema,
newlinesBetween: newlinesBetweenJsonSchema,
ignoreCase: ignoreCaseJsonSchema,
alphabet: alphabetJsonSchema,
type: buildTypeJsonSchema(),
locales: localesJsonSchema,
groups: groupsJsonSchema,
order: orderJsonSchema,
},
additionalProperties: false,
type: 'object',
}

export default createEslintRule<Options, MESSAGE_ID>({
meta: {
schema: [
{
properties: {
partitionByComment: {
...partitionByCommentJsonSchema,
description:
'Allows you to use comments to separate the union types into logical groups.',
},
partitionByNewLine: partitionByNewLineJsonSchema,
specialCharacters: specialCharactersJsonSchema,
newlinesBetween: newlinesBetweenJsonSchema,
ignoreCase: ignoreCaseJsonSchema,
alphabet: alphabetJsonSchema,
type: buildTypeJsonSchema(),
locales: localesJsonSchema,
groups: groupsJsonSchema,
order: orderJsonSchema,
},
additionalProperties: false,
type: 'object',
},
],
messages: {
unexpectedUnionTypesGroupOrder:
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
Expand All @@ -137,6 +137,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
description: 'Enforce sorted union types.',
recommended: true,
},
schema: [jsonSchema],
type: 'suggestion',
fixable: 'code',
},
Expand Down

0 comments on commit 93a62e0

Please sign in to comment.