New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@secretlint/config-loader

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secretlint/config-loader - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

lib/AggregationError.d.ts

33

lib/index.d.ts

@@ -1,7 +0,4 @@

import { SecretLintConfigDescriptor, SecretLintCoreDescriptor, SecretLintUnionRuleCreator, SecretLintRuleModule } from "@secretlint/types";
import { SecretLintCoreConfig, SecretLintConfigDescriptor, SecretLintUnionRuleCreator, SecretLintRuleModule } from "@secretlint/types";
import { AggregationError } from "./AggregationError";
export declare function importSecretlintCreator(moduleExports?: SecretLintRuleModule): SecretLintUnionRuleCreator;
export declare class AggregateError extends Error {
errors: Error[];
constructor(errors: Error[], message: string);
}
export declare type SecretLintConfigLoaderOptions = {

@@ -27,3 +24,10 @@ cwd?: string;

ok: true;
config: SecretLintCoreDescriptor;
/**
* Full config object
*/
config: SecretLintCoreConfig;
/**
* Partial config file represent
*/
configDescriptor: SecretLintConfigDescriptor;
configFilePath: string;

@@ -34,3 +38,3 @@ };

configFilePath: string;
rawConfig: SecretLintConfigDescriptor;
configDescriptor: SecretLintConfigDescriptor;
};

@@ -41,3 +45,3 @@ export declare type SecretLintLoadPackagesFromRawConfigOptions = {

*/
rawConfig: SecretLintConfigDescriptor;
configDescriptor: SecretLintConfigDescriptor;
/**

@@ -60,3 +64,3 @@ * node_modules directory path

ok: true;
config: SecretLintCoreDescriptor;
config: SecretLintCoreConfig;
};

@@ -67,3 +71,3 @@ /**

*/
export declare const loadPackagesFromRawConfig: (options: SecretLintLoadPackagesFromRawConfigOptions) => Promise<SecretLintLoadPackagesFromRawConfigResult>;
export declare const loadPackagesFromConfigDescriptor: (options: SecretLintLoadPackagesFromRawConfigOptions) => Promise<SecretLintLoadPackagesFromRawConfigResult>;
/**

@@ -79,2 +83,9 @@ * Load config file and return config object that is loaded rule instance.

*/
export declare const loadRawConfig: (options: SecretLintConfigLoaderOptions) => Promise<SecretLintConfigLoaderRawResult>;
export declare const loadConfigDescriptor: (options: SecretLintConfigLoaderOptions) => Promise<SecretLintConfigLoaderRawResult>;
export declare type validateConfigResult = {
ok: true;
} | {
ok: false;
error: AggregationError | Error;
};
export declare const validateConfig: (options: SecretLintConfigLoaderOptions) => Promise<validateConfigResult>;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -22,8 +26,9 @@ if (k2 === undefined) k2 = k;

Object.defineProperty(exports, "__esModule", { value: true });
exports.loadRawConfig = exports.loadConfig = exports.loadPackagesFromRawConfig = exports.AggregateError = exports.importSecretlintCreator = void 0;
exports.validateConfig = exports.loadConfigDescriptor = exports.loadConfig = exports.loadPackagesFromConfigDescriptor = exports.importSecretlintCreator = void 0;
const rc_config_loader_1 = require("rc-config-loader");
const profiler_1 = require("@secretlint/profiler");
const SecretLintModuleResolver_1 = require("./SecretLintModuleResolver");
const config_validator_1 = require("@secretlint/config-validator");
const validator_1 = require("./validator");
const url = __importStar(require("url"));
const AggregationError_1 = require("./AggregationError");
function importSecretlintCreator(moduleExports) {

@@ -39,10 +44,2 @@ if (!moduleExports) {

exports.importSecretlintCreator = importSecretlintCreator;
class AggregateError extends Error {
constructor(errors, message) {
const detailsMessage = errors.map((error) => error.message).join("\n\n");
super(message + "\n\n" + detailsMessage);
this.errors = errors;
}
}
exports.AggregateError = AggregateError;
// Windows's path require to convert file://

@@ -60,7 +57,8 @@ // https://github.com/secretlint/secretlint/issues/205

*/
const loadPackagesFromRawConfig = async (options) => {
const loadPackagesFromConfigDescriptor = async (options) => {
var _a;
// Early validation, validate rawConfig by JSON Schema
const resultValidateRawConfig = (0, config_validator_1.validateRawConfig)(options.rawConfig);
if (!resultValidateRawConfig.ok) {
throw resultValidateRawConfig.error;
const validateConfigDescriptorResult = (0, validator_1.validateConfigDescriptor)(options.configDescriptor);
if (!validateConfigDescriptorResult.ok) {
throw validateConfigDescriptorResult.error;
}

@@ -74,5 +72,9 @@ profiler_1.secretLintProfiler.mark({

});
// TODO: remove any
const isSecretLintCoreConfigRulePreset = (v) => {
return v.meta.type === "preset";
};
const errors = [];
const rules = [];
for (const configDescriptorRule of options.rawConfig.rules) {
for (const configDescriptorRule of options.configDescriptor.rules) {
try {

@@ -88,17 +90,31 @@ profiler_1.secretLintProfiler.mark({

// TODO: any to be remove
const ruleModule = replacedDefinition
const ruleCreator = replacedDefinition
? replacedDefinition.rule
: importSecretlintCreator(await _importDynamic(convertToFileUrl(moduleResolver.resolveRulePackageName(configDescriptorRule.id))));
const secretLintConfigDescriptorRules = "rules" in configDescriptorRule && Array.isArray(configDescriptorRule.rules)
? configDescriptorRule.rules.filter((rule) => rule !== undefined)
: undefined;
rules.push({
id: configDescriptorRule.id,
rule: ruleModule,
rules: secretLintConfigDescriptorRules,
options: configDescriptorRule.options,
severity: "severity" in configDescriptorRule ? configDescriptorRule.severity : undefined,
disabled: configDescriptorRule.disabled,
allowMessageIds: "allowMessageIds" in configDescriptorRule ? configDescriptorRule.allowMessageIds : undefined,
});
if (isSecretLintCoreConfigRulePreset(ruleCreator)) {
const configDescriptorRulePreset = configDescriptorRule;
rules.push({
id: configDescriptorRule.id,
rule: ruleCreator,
// options for rules
rules: (_a = configDescriptorRulePreset === null || configDescriptorRulePreset === void 0 ? void 0 : configDescriptorRulePreset.rules) === null || _a === void 0 ? void 0 : _a.map((rule) => {
return {
...rule,
type: "rule",
};
}),
options: configDescriptorRule.options,
disabled: configDescriptorRule.disabled,
});
}
else {
rules.push({
id: configDescriptorRule.id,
rule: ruleCreator,
options: configDescriptorRule.options,
severity: "severity" in configDescriptorRule ? configDescriptorRule.severity : undefined,
disabled: configDescriptorRule.disabled,
allowMessageIds: "allowMessageIds" in configDescriptorRule ? configDescriptorRule.allowMessageIds : undefined,
});
}
profiler_1.secretLintProfiler.mark({

@@ -117,6 +133,6 @@ type: "@config-loader>resolve-module::end",

if (errors.length > 0) {
throw new AggregateError(errors, "secretlint loading errors");
throw new AggregationError_1.AggregationError(errors, "secretlint loading errors");
}
const loadedConfig = {
sharedOptions: options.rawConfig.sharedOptions,
sharedOptions: options.configDescriptor.sharedOptions,
rules,

@@ -126,3 +142,5 @@ };

// This validator require actual `rule` creator for `disabledMessage` option.
const resultValidateConfig = (0, config_validator_1.validateConfig)(loadedConfig);
const resultValidateConfig = (0, validator_1.validateConfigWithDescriptor)({
config: loadedConfig,
});
if (!resultValidateConfig.ok) {

@@ -136,3 +154,3 @@ throw resultValidateConfig.error;

};
exports.loadPackagesFromRawConfig = loadPackagesFromRawConfig;
exports.loadPackagesFromConfigDescriptor = loadPackagesFromConfigDescriptor;
/**

@@ -146,3 +164,3 @@ * Load config file and return config object that is loaded rule instance.

});
const rawResult = await (0, exports.loadRawConfig)(options);
const { configDescriptor, configFilePath } = await (0, exports.loadConfigDescriptor)(options);
profiler_1.secretLintProfiler.mark({

@@ -154,4 +172,4 @@ type: "@config-loader>load-config-file::end",

});
const result = await (0, exports.loadPackagesFromRawConfig)({
rawConfig: rawResult.rawConfig,
const configLoadResult = await (0, exports.loadPackagesFromConfigDescriptor)({
configDescriptor,
node_moduleDir: options.node_moduleDir,

@@ -165,4 +183,5 @@ testReplaceDefinitions: options.testReplaceDefinitions,

ok: true,
config: result.config,
configFilePath: rawResult.configFilePath,
config: configLoadResult.config,
configDescriptor,
configFilePath,
};

@@ -176,3 +195,3 @@ };

*/
const loadRawConfig = async (options) => {
const loadConfigDescriptor = async (options) => {
const results = (0, rc_config_loader_1.rcFile)("secretlint", {

@@ -194,7 +213,22 @@ cwd: options.cwd,

ok: true,
rawConfig: results.config,
configDescriptor: results.config,
configFilePath: results.filePath,
};
};
exports.loadRawConfig = loadRawConfig;
exports.loadConfigDescriptor = loadConfigDescriptor;
const validateConfig = async (options) => {
try {
await (0, exports.loadConfig)(options);
return {
ok: true,
};
}
catch (error) {
return {
ok: false,
error: error instanceof Error ? error : new Error(String(error)),
};
}
};
exports.validateConfig = validateConfig;
//# sourceMappingURL=index.js.map

@@ -5,3 +5,7 @@ // LICENSE : MIT

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -8,0 +12,0 @@ if (k2 === undefined) k2 = k;

{
"name": "@secretlint/config-loader",
"version": "4.2.0",
"version": "5.0.0",
"description": "Config loader for secretlint.",

@@ -33,7 +33,9 @@ "keywords": [

"scripts": {
"build": "tsc -p .",
"build": "npm run create-validation && tsc -p .",
"clean": "rimraf lib/",
"create-validation": "create-validator-ts src/descriptor-types.ts --additionalProperties",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepublish": "npm run --if-present build",
"test": "mocha \"test/**/*.ts\"",
"updateSnapshot": "UPDATE_SNAPSHOT=1 npm test",
"watch": "tsc -p . --watch"

@@ -47,5 +49,5 @@ },

"dependencies": {
"@secretlint/config-validator": "^4.2.0",
"@secretlint/profiler": "^4.2.0",
"@secretlint/types": "^4.2.0",
"@secretlint/profiler": "^5.0.0",
"@secretlint/types": "^5.0.0",
"ajv": "^8.10.0",
"debug": "^4.1.1",

@@ -56,5 +58,6 @@ "rc-config-loader": "^4.0.0",

"devDependencies": {
"@secretlint/secretlint-rule-internal-test-pure-deps": "^4.2.0",
"@secretlint/secretlint-rule-internal-test-pure-deps": "^5.0.0",
"@types/mocha": "^9.0.0",
"@types/node": "^16.9.1",
"@types/node": "^17.0.21",
"create-validator-ts": "^3.0.1",
"mocha": "^9.0.1",

@@ -68,3 +71,3 @@ "prettier": "^2.3.1",

"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": "^14.13.1 || >=16.0.0"
},

@@ -74,3 +77,3 @@ "publishConfig": {

},
"gitHead": "7879c01d93ae5932822c2864e9bb51e7a6627f0f"
"gitHead": "4c1b6508b78a3c1f3e9175a8b36e56caa369a302"
}

@@ -60,2 +60,15 @@ # @secretlint/config-loader

## Terminology
- ConfigDescriptor: config file literal that is not loaded yet
- Config: loaded object
## Workflow
- Validate `ConfigDescriptor`
- Load `ConfigDescriptor` and create `Config` object - imports each rule modules
- Validate Loaded `Config` with `ConfigDescriptor`
- Invalid option, Invalid allowMessageIds, Invalid id specify for a preset
- If all validation is passed, get a Config.
## Changelog

@@ -62,0 +75,0 @@

import { rcFile } from "rc-config-loader";
import {
SecretLintCoreConfig,
SecretLintCoreConfigUnionRule,
SecretLintConfigDescriptor,
SecretLintCoreDescriptor,
SecretLintCoreDescriptorRule,
SecretLintCoreDescriptorUnionRule,
SecretLintUnionRuleCreator,
SecretLintRuleModule,
SecretLintRulePresetCreator,
SecretLintConfigDescriptorRulePreset,
} from "@secretlint/types";
import { secretLintProfiler } from "@secretlint/profiler";
import { SecretLintModuleResolver } from "./SecretLintModuleResolver";
import { validateConfig, validateRawConfig } from "@secretlint/config-validator";
import { validateConfigWithDescriptor, validateConfigDescriptor } from "./validator";
import * as url from "url";
import { AggregationError } from "./AggregationError";

@@ -25,12 +27,2 @@ export function importSecretlintCreator(moduleExports?: SecretLintRuleModule): SecretLintUnionRuleCreator {

export class AggregateError extends Error {
errors: Error[];
constructor(errors: Error[], message: string) {
const detailsMessage = errors.map((error) => error.message).join("\n\n");
super(message + "\n\n" + detailsMessage);
this.errors = errors;
}
}
// Windows's path require to convert file://

@@ -65,3 +57,10 @@ // https://github.com/secretlint/secretlint/issues/205

ok: true;
config: SecretLintCoreDescriptor; // Core Option object
/**
* Full config object
*/
config: SecretLintCoreConfig;
/**
* Partial config file represent
*/
configDescriptor: SecretLintConfigDescriptor;
configFilePath: string;

@@ -73,3 +72,4 @@ };

configFilePath: string;
rawConfig: SecretLintConfigDescriptor; // Config Raw object
// Config Raw object
configDescriptor: SecretLintConfigDescriptor;
};

@@ -80,3 +80,3 @@ export type SecretLintLoadPackagesFromRawConfigOptions = {

*/
rawConfig: SecretLintConfigDescriptor;
configDescriptor: SecretLintConfigDescriptor;
/**

@@ -99,3 +99,3 @@ * node_modules directory path

ok: true;
config: SecretLintCoreDescriptor; // Core Option object
config: SecretLintCoreConfig; // Core Option object
};

@@ -107,9 +107,9 @@

*/
export const loadPackagesFromRawConfig = async (
export const loadPackagesFromConfigDescriptor = async (
options: SecretLintLoadPackagesFromRawConfigOptions
): Promise<SecretLintLoadPackagesFromRawConfigResult> => {
// Early validation, validate rawConfig by JSON Schema
const resultValidateRawConfig = validateRawConfig(options.rawConfig);
if (!resultValidateRawConfig.ok) {
throw resultValidateRawConfig.error;
const validateConfigDescriptorResult = validateConfigDescriptor(options.configDescriptor);
if (!validateConfigDescriptorResult.ok) {
throw validateConfigDescriptorResult.error;
}

@@ -123,5 +123,9 @@ secretLintProfiler.mark({

});
// TODO: remove any
const isSecretLintCoreConfigRulePreset = (v: SecretLintUnionRuleCreator): v is SecretLintRulePresetCreator => {
return v.meta.type === "preset";
};
const errors: Error[] = [];
const rules: SecretLintCoreDescriptorUnionRule[] = [];
for (const configDescriptorRule of options.rawConfig.rules) {
const rules: SecretLintCoreConfigUnionRule[] = [];
for (const configDescriptorRule of options.configDescriptor.rules) {
try {

@@ -138,3 +142,3 @@ secretLintProfiler.mark({

// TODO: any to be remove
const ruleModule: any = replacedDefinition
const ruleCreator: SecretLintUnionRuleCreator = replacedDefinition
? replacedDefinition.rule

@@ -146,18 +150,28 @@ : importSecretlintCreator(

);
const secretLintConfigDescriptorRules: SecretLintCoreDescriptorRule[] | undefined =
"rules" in configDescriptorRule && Array.isArray(configDescriptorRule.rules)
? (configDescriptorRule.rules.filter(
(rule) => rule !== undefined
) as SecretLintCoreDescriptorRule[])
: undefined;
rules.push({
id: configDescriptorRule.id,
rule: ruleModule,
rules: secretLintConfigDescriptorRules,
options: configDescriptorRule.options,
severity: "severity" in configDescriptorRule ? configDescriptorRule.severity : undefined,
disabled: configDescriptorRule.disabled,
allowMessageIds:
"allowMessageIds" in configDescriptorRule ? configDescriptorRule.allowMessageIds : undefined,
});
if (isSecretLintCoreConfigRulePreset(ruleCreator)) {
const configDescriptorRulePreset = configDescriptorRule as SecretLintConfigDescriptorRulePreset;
rules.push({
id: configDescriptorRule.id,
rule: ruleCreator,
// options for rules
rules: configDescriptorRulePreset?.rules?.map((rule) => {
return {
...rule,
type: "rule",
};
}),
options: configDescriptorRule.options,
disabled: configDescriptorRule.disabled,
});
} else {
rules.push({
id: configDescriptorRule.id,
rule: ruleCreator,
options: configDescriptorRule.options,
severity: "severity" in configDescriptorRule ? configDescriptorRule.severity : undefined,
disabled: configDescriptorRule.disabled,
allowMessageIds:
"allowMessageIds" in configDescriptorRule ? configDescriptorRule.allowMessageIds : undefined,
});
}
secretLintProfiler.mark({

@@ -175,6 +189,6 @@ type: "@config-loader>resolve-module::end",

if (errors.length > 0) {
throw new AggregateError(errors, "secretlint loading errors");
throw new AggregationError(errors, "secretlint loading errors");
}
const loadedConfig: SecretLintCoreDescriptor = {
sharedOptions: options.rawConfig.sharedOptions,
const loadedConfig: SecretLintCoreConfig = {
sharedOptions: options.configDescriptor.sharedOptions,
rules,

@@ -184,3 +198,5 @@ };

// This validator require actual `rule` creator for `disabledMessage` option.
const resultValidateConfig = validateConfig(loadedConfig);
const resultValidateConfig = validateConfigWithDescriptor({
config: loadedConfig,
});
if (!resultValidateConfig.ok) {

@@ -202,3 +218,3 @@ throw resultValidateConfig.error;

});
const rawResult = await loadRawConfig(options);
const { configDescriptor, configFilePath } = await loadConfigDescriptor(options);
secretLintProfiler.mark({

@@ -210,4 +226,4 @@ type: "@config-loader>load-config-file::end",

});
const result = await loadPackagesFromRawConfig({
rawConfig: rawResult.rawConfig,
const configLoadResult = await loadPackagesFromConfigDescriptor({
configDescriptor,
node_moduleDir: options.node_moduleDir,

@@ -221,4 +237,5 @@ testReplaceDefinitions: options.testReplaceDefinitions,

ok: true,
config: result.config,
configFilePath: rawResult.configFilePath,
config: configLoadResult.config,
configDescriptor,
configFilePath,
};

@@ -231,3 +248,3 @@ };

*/
export const loadRawConfig = async (
export const loadConfigDescriptor = async (
options: SecretLintConfigLoaderOptions

@@ -251,5 +268,27 @@ ): Promise<SecretLintConfigLoaderRawResult> => {

ok: true,
rawConfig: results.config,
configDescriptor: results.config,
configFilePath: results.filePath,
};
};
export type validateConfigResult =
| {
ok: true;
}
| {
ok: false;
error: AggregationError | Error;
};
export const validateConfig = async (options: SecretLintConfigLoaderOptions): Promise<validateConfigResult> => {
try {
await loadConfig(options);
return {
ok: true,
};
} catch (error) {
return {
ok: false,
error: error instanceof Error ? error : new Error(String(error)),
};
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc