@eslint-react/kit
Advanced tools
Comparing version
import { _ } from '@eslint-react/eff'; | ||
import * as tseslint from '@typescript-eslint/utils/ts-eslint'; | ||
import { ReportDescriptor } from '@typescript-eslint/utils/ts-eslint'; | ||
import { TsConfigJson } from 'get-tsconfig'; | ||
import { CompilerOptions, JsxEmit } from 'typescript'; | ||
@@ -39,18 +39,10 @@ /** | ||
type JsxRuntimeOptions = Pick<TsConfigJson.CompilerOptions, "reactNamespace" | "jsx" | "jsxFactory" | "jsxFragmentFactory" | "jsxImportSource">; | ||
declare const defaultJsxRuntimeOptions: { | ||
readonly jsx: "react-jsx"; | ||
readonly jsxFactory: "React.createElement"; | ||
readonly jsxFragmentFactory: "React.Fragment"; | ||
readonly jsxImportSource: "react"; | ||
readonly reactNamespace: "React"; | ||
}; | ||
type JsxRuntimeOptions = Pick<CompilerOptions, "reactNamespace" | "jsx" | "jsxFactory" | "jsxFragmentFactory" | "jsxImportSource">; | ||
/** | ||
* Get JsxRuntimeOptions from RuleContext | ||
* @param context The RuleContext | ||
* @returns JsxRuntimeOptions | ||
*/ | ||
declare function getJsxRuntimeOptionsFromContext(context: RuleContext): { | ||
readonly jsx: "react-jsx"; | ||
readonly jsxFactory: "React.createElement"; | ||
readonly jsxFragmentFactory: "React.Fragment"; | ||
readonly jsxImportSource: "react"; | ||
readonly reactNamespace: "React"; | ||
} | { | ||
jsx: TsConfigJson.CompilerOptions.JSX; | ||
jsx: JsxEmit; | ||
jsxFactory: string; | ||
@@ -63,6 +55,5 @@ jsxFragmentFactory: string; | ||
type index_JsxRuntimeOptions = JsxRuntimeOptions; | ||
declare const index_defaultJsxRuntimeOptions: typeof defaultJsxRuntimeOptions; | ||
declare const index_getJsxRuntimeOptionsFromContext: typeof getJsxRuntimeOptionsFromContext; | ||
declare namespace index { | ||
export { type index_JsxRuntimeOptions as JsxRuntimeOptions, index_defaultJsxRuntimeOptions as defaultJsxRuntimeOptions, index_getJsxRuntimeOptionsFromContext as getJsxRuntimeOptionsFromContext }; | ||
export { type index_JsxRuntimeOptions as JsxRuntimeOptions, index_getJsxRuntimeOptionsFromContext as getJsxRuntimeOptionsFromContext }; | ||
} | ||
@@ -69,0 +60,0 @@ |
'use strict'; | ||
var getTsconfig = require('get-tsconfig'); | ||
var typescript = require('typescript'); | ||
@@ -14,23 +14,12 @@ var __defProp = Object.defineProperty; | ||
__export(JsxRuntime_exports, { | ||
defaultJsxRuntimeOptions: () => defaultJsxRuntimeOptions, | ||
getJsxRuntimeOptionsFromContext: () => getJsxRuntimeOptionsFromContext | ||
}); | ||
var defaultJsxRuntimeOptions = { | ||
jsx: "react-jsx", | ||
jsxFactory: "React.createElement", | ||
jsxFragmentFactory: "React.Fragment", | ||
jsxImportSource: "react", | ||
reactNamespace: "React" | ||
}; | ||
var tsconfigCache = /* @__PURE__ */ new Map(); | ||
function getJsxRuntimeOptionsFromContext(context) { | ||
const tsconfigResult = getTsconfig.getTsconfig(context.cwd, "tsconfig.json", tsconfigCache); | ||
const compilerOptions = tsconfigResult?.config.compilerOptions; | ||
if (compilerOptions == null) return defaultJsxRuntimeOptions; | ||
const options = context.sourceCode.parserServices?.program?.getCompilerOptions() ?? {}; | ||
return { | ||
jsx: compilerOptions.jsx ?? defaultJsxRuntimeOptions.jsx, | ||
jsxFactory: compilerOptions.jsxFactory ?? defaultJsxRuntimeOptions.jsxFactory, | ||
jsxFragmentFactory: compilerOptions.jsxFragmentFactory ?? defaultJsxRuntimeOptions.jsxFragmentFactory, | ||
jsxImportSource: compilerOptions.jsxImportSource ?? defaultJsxRuntimeOptions.jsxImportSource, | ||
reactNamespace: compilerOptions.reactNamespace ?? defaultJsxRuntimeOptions.reactNamespace | ||
jsx: options.jsx ?? typescript.JsxEmit.ReactJSX, | ||
jsxFactory: options.jsxFactory ?? "React.createElement", | ||
jsxFragmentFactory: options.jsxFragmentFactory ?? "React.Fragment", | ||
jsxImportSource: options.jsxImportSource ?? "react", | ||
reactNamespace: options.reactNamespace ?? "React" | ||
}; | ||
@@ -37,0 +26,0 @@ } |
{ | ||
"name": "@eslint-react/kit", | ||
"version": "1.40.0-beta.1", | ||
"version": "1.40.0-beta.2", | ||
"description": "ESLint React's Plugin Kit for building plugins and rules.", | ||
@@ -39,5 +39,4 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
"@typescript-eslint/utils": "^8.29.0", | ||
"get-tsconfig": "^4.10.0", | ||
"ts-pattern": "^5.7.0", | ||
"@eslint-react/eff": "1.40.0-beta.1" | ||
"@eslint-react/eff": "1.40.0-beta.2" | ||
}, | ||
@@ -44,0 +43,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3
-25%13962
-13.76%211
-12.81%+ Added
- Removed
- Removed
- Removed
- Removed