@ts-safeql/eslint-plugin
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -16,4 +16,4 @@ "use strict"; | ||
} | ||
return (0, fp_ts_1.pipe)(getConfigFromFile(params.projectDir), fp_ts_1.E.getOrElseW(({ type, message }) => { | ||
throw new Error(`safeql: ${type} ${message}`); | ||
return (0, fp_ts_1.pipe)(getConfigFromFile(params.projectDir), fp_ts_1.E.getOrElseW((message) => { | ||
throw new Error(`safeql: ${message}`); | ||
})); | ||
@@ -23,24 +23,37 @@ } | ||
function getConfigFromFile(projectDir) { | ||
return (0, fp_ts_1.pipe)(fp_ts_1.E.Do, fp_ts_1.E.bindW("configFilePath", () => fp_ts_1.E.right(path_1.default.join(projectDir, "safeql.config.ts"))), fp_ts_1.E.bindW("tempFileName", () => fp_ts_1.E.right(`safeql.config.temp-${Date.now()}.js`)), fp_ts_1.E.bindW("tempFilePath", ({ tempFileName }) => fp_ts_1.E.right(path_1.default.join(projectDir, tempFileName))), fp_ts_1.E.chainW((params) => { | ||
return fs_1.default.existsSync(params.configFilePath) | ||
? fp_ts_1.E.right(params) | ||
: fp_ts_1.E.left({ type: "NOT_FOUND", message: "safeql.config.ts not found" }); | ||
}), fp_ts_1.E.chainFirstW(({ configFilePath, tempFilePath }) => { | ||
return fp_ts_1.E.tryCatch(() => { | ||
const result = esbuild_1.default.buildSync({ | ||
entryPoints: [configFilePath], | ||
write: false, | ||
format: "cjs", | ||
}); | ||
return fs_1.default.writeFileSync(tempFilePath, result.outputFiles[0].text); | ||
}, (error) => ({ type: "ESBUILD_ERROR", message: `${error}` })); | ||
}), fp_ts_1.E.bindW("rawConfig", ({ tempFilePath }) => { | ||
return fp_ts_1.E.tryCatch(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
return require(tempFilePath).default; | ||
}, (error) => ({ | ||
type: "INVALID", | ||
message: `${error}`, | ||
})); | ||
}), fp_ts_1.E.bindW("config", ({ rawConfig }) => fp_ts_1.E.tryCatch(() => check_sql_rule_1.Config.parse(rawConfig), (error) => ({ type: "INVALID", message: `${error}` }))), fp_ts_1.E.chainFirstW(({ tempFilePath }) => fp_ts_1.E.tryCatch(() => fs_1.default.unlinkSync(tempFilePath), (error) => ({ type: "INVALID", message: `${error}` }))), fp_ts_1.E.map(({ config }) => config)); | ||
const configFilePath = path_1.default.join(projectDir, "safeql.config.ts"); | ||
const tempFileName = `safeql.config.temp-${Date.now()}.js`; | ||
const tempFilePath = path_1.default.join(projectDir, tempFileName); | ||
const removeIfExists = (filePath) => { | ||
if (fs_1.default.existsSync(filePath)) { | ||
fs_1.default.unlinkSync(filePath); | ||
} | ||
}; | ||
try { | ||
if (!fs_1.default.existsSync(configFilePath)) { | ||
throw new Error(`safeql.config.ts was not found at ${projectDir}`); | ||
} | ||
const result = esbuild_1.default.buildSync({ | ||
entryPoints: [configFilePath], | ||
write: false, | ||
format: "cjs", | ||
}); | ||
fs_1.default.writeFileSync(tempFilePath, result.outputFiles[0].text); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const rawConfig = require(tempFilePath).default; | ||
if (rawConfig === undefined) { | ||
throw new Error(`safeql.config.ts must export a default value`); | ||
} | ||
const config = check_sql_rule_1.Config.safeParse(rawConfig); | ||
if (!config.success) { | ||
throw new Error(`safeql.config.ts is invalid: ${config.error.message}`); | ||
} | ||
return fp_ts_1.E.right(config.data); | ||
} | ||
catch (error) { | ||
return fp_ts_1.E.left(`${error}`); | ||
} | ||
finally { | ||
removeIfExists(tempFilePath); | ||
} | ||
} | ||
@@ -47,0 +60,0 @@ function isConfigFileRuleOptions(options) { |
{ | ||
"name": "@ts-safeql/eslint-plugin", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3374
175129