Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@inlang/core

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inlang/core - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

dist/lint/test-utilities.d.ts

2

dist/lint/context.d.ts

@@ -39,3 +39,3 @@ import type { Resource, Message, Pattern } from "../ast/schema.js";

*/
export declare const parseLintConfigArguments: <T>(args: LintConfigArguments<T> | undefined, defaultLevel: LintLevel) => {
export declare const parseLintConfigArguments: <T>(args: [] | [boolean | LintLevel] | [boolean | LintLevel, (T | undefined)?] | undefined, defaultLevel: LintLevel) => {
level: false | LintLevel;

@@ -42,0 +42,0 @@ settings: T | undefined;

@@ -11,3 +11,3 @@ import type { LintedNode, LintReport, LintLevel } from "./context.js";

*/
export declare const getLintReports: (node: LintedNode, nested?: boolean) => LintReport[];
export declare const getLintReports: (node: LintedNode | LintedNode[], nested?: boolean) => LintReport[];
/**

@@ -22,3 +22,3 @@ * Extracts all lint reports with a certain lint level that are present on the given node.

*/
export declare const getLintReportsByLevel: (level: LintLevel, node: LintedNode, nested?: boolean) => LintReport[];
export declare const getLintReportsByLevel: (level: LintLevel, node: LintedNode | LintedNode[], nested?: boolean) => LintReport[];
/**

@@ -32,3 +32,3 @@ * Extracts all lint reports with the 'error' lint level that are present on the given node.

*/
export declare const getLintErrors: (node: LintedNode, nested?: boolean | undefined) => LintReport[];
export declare const getLintErrors: (node: LintedNode | LintedNode[], nested?: boolean | undefined) => LintReport[];
/**

@@ -42,3 +42,3 @@ * Extracts all lint reports with the 'warn' lint level that are present on the given node.

*/
export declare const getLintWarnings: (node: LintedNode, nested?: boolean | undefined) => LintReport[];
export declare const getLintWarnings: (node: LintedNode | LintedNode[], nested?: boolean | undefined) => LintReport[];
/**

@@ -53,3 +53,3 @@ * Extracts all lint reports with a certain lint id that are present on the given node.

*/
export declare const getLintReportsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => LintReport[];
export declare const getLintReportsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => LintReport[];
/**

@@ -64,3 +64,3 @@ * Extracts all lint reports with a certain lint id and the 'error' lint level that are present on the given node.

*/
export declare const getLintErrorsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => LintReport[];
export declare const getLintErrorsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => LintReport[];
/**

@@ -75,3 +75,3 @@ * Extracts all lint reports with a certain lint id and the 'warn' lint level that are present on the given node.

*/
export declare const getLintWarningsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => LintReport[];
export declare const getLintWarningsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => LintReport[];
/**

@@ -85,3 +85,3 @@ * Checks if a given node has lint reports attached to it.

*/
export declare const hasLintReports: (node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintReports: (node: LintedNode | LintedNode[], nested?: boolean) => boolean;
/**

@@ -95,3 +95,3 @@ * Checks if a given node has lint reports with the 'error' lint level attached to it.

*/
export declare const hasLintErrors: (node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintErrors: (node: LintedNode | LintedNode[], nested?: boolean) => boolean;
/**

@@ -105,3 +105,3 @@ * Checks if a given node has lint reports with the 'warn' lint level attached to it.

*/
export declare const hasLintWarnings: (node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintWarnings: (node: LintedNode | LintedNode[], nested?: boolean) => boolean;
/**

@@ -115,3 +115,3 @@ * Checks if a given node has lint reports with a certain lint id attached to it.

*/
export declare const hasLintReportsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintReportsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => boolean;
/**

@@ -125,3 +125,3 @@ * Checks if a given node has lint reports with a certain lint id and the 'error' lint level attached to it.

*/
export declare const hasLintErrorsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintErrorsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => boolean;
/**

@@ -135,2 +135,2 @@ * Checks if a given node has lint reports with a certain lint id and the 'warn' lint level attached to it.

*/
export declare const hasLintWarningsWithId: (id: LintRuleId, node: LintedNode, nested?: boolean) => boolean;
export declare const hasLintWarningsWithId: (id: LintRuleId, node: LintedNode | LintedNode[], nested?: boolean) => boolean;

@@ -1,2 +0,2 @@

import { unhandled } from '../utilities/debug.js';
import { unhandled } from "../utilities/debug.js";
/**

@@ -11,2 +11,5 @@ * Extracts all lint reports that are present on the given node.

export const getLintReports = (node, nested = true) => {
if (Array.isArray(node)) {
return node.flatMap((n) => getLintReports(n, nested));
}
const { type } = node;

@@ -34,3 +37,3 @@ switch (type) {

];
const getLintReportsFromPattern = ({ lint, }) => lint || [];
const getLintReportsFromPattern = ({ lint }) => lint || [];
// --------------------------------------------------------------------------------------------------------------------

@@ -37,0 +40,0 @@ /**

@@ -80,2 +80,6 @@ import { describe, expect, test } from "vitest";

});
test("should support an array of nodes", async () => {
const reports = getLintReports([resource, message, pattern]);
expect(reports).toHaveLength(21);
});
test("should throw an error if node type does not get handled", async () => {

@@ -82,0 +86,0 @@ expect(() => getLintReports({ type: "unknown" })).toThrow();

import type { Message, Pattern, Resource } from "../ast/index.js";
import type { Config, EnvironmentFunctions } from "../config/schema.js";
import type { MaybePromise } from '../utilities/types.js';
import type { MaybePromise } from "../utilities/types.js";
import { LintLevel, Context } from "./context.js";

@@ -33,3 +33,3 @@ export type LintableNode = Resource | Message | Pattern;

};
export type LintConfigArguments<Settings> = [] | [boolean | LintLevel] | [LintLevel, Settings?];
export type LintConfigArguments<Settings = never, RequireSettings extends boolean = false> = RequireSettings extends true ? [boolean | LintLevel, Settings] : [] | [boolean | LintLevel] | [boolean | LintLevel, Settings?];
/**

@@ -47,12 +47,16 @@ * The unique id of a lint rule.

*
* @example a rule that does not expects any parameters
* @example a rule that does not expects any settings
* ```
* const myRule: LintRuleInitializer = // implementation
* ```
* @example a rule that accepts parameters
* @example a rule that accepts settings
* ```
* const myRule: LintRuleInitializer<{ strict: boolean }> = // implementation
* ```
* @example a rule that requires settings
* ```
* const myRule: LintRuleInitializer<{ strict: boolean }, true> = // implementation
* ```
*/
export type LintRuleInitializer<Settings = never> = (...args: LintConfigArguments<Settings>) => LintRule;
export type LintRuleInitializer<Settings = never, RequireSettings extends boolean = false> = (...args: LintConfigArguments<Settings, RequireSettings>) => LintRule;
/**

@@ -95,3 +99,3 @@ * A lint rule that was configured with the lint level and lint specific settings.

*/
export declare const createLintRule: <Settings>(id: LintRuleId, defaultLevel: LintLevel, configureLintRule: (settings?: Settings | undefined) => Omit<LintRule, "id" | "level">) => (...args: LintConfigArguments<Settings>) => {
export declare const createLintRule: <Settings = never, RequireSettings extends boolean = false>(id: LintRuleId, defaultLevel: LintLevel, configureLintRule: (settings?: Settings | undefined) => Omit<LintRule, "id" | "level">) => (...args: LintConfigArguments<Settings, RequireSettings>) => {
id: `${string}.${string}`;

@@ -98,0 +102,0 @@ level: false | LintLevel;

@@ -48,2 +48,36 @@ import { expectType } from "tsd";

expectType({});
rule();
rule("warn");
rule("error");
rule(false);
rule(true);
rule(true, undefined);
// @ts-expect-error does not accept settings
rule(true, { debug: true });
// ----------------------------------------------------------------------------
const ruleWithOptionalSettings = createLintRule("a.b", "error", () => ({
setup: () => undefined,
visitors: {},
}));
ruleWithOptionalSettings();
ruleWithOptionalSettings("error");
ruleWithOptionalSettings("error", { test: true });
ruleWithOptionalSettings("warn");
ruleWithOptionalSettings("warn", { test: true });
ruleWithOptionalSettings(false);
ruleWithOptionalSettings(false, { test: true });
ruleWithOptionalSettings(true);
ruleWithOptionalSettings(true, { test: true });
// ----------------------------------------------------------------------------
const ruleWithRequiredSettings = createLintRule("a.b", "error", () => ({
setup: () => undefined,
visitors: {},
}));
// @ts-expect-error requires settings to be passed
ruleWithRequiredSettings();
// @ts-expect-error requires settings to be passed
ruleWithRequiredSettings("warn");
// @ts-expect-error requires correct settings object to be passed
ruleWithRequiredSettings(true, {});
ruleWithRequiredSettings(true, { test: true });
// configured rule ------------------------------------------------------------

@@ -50,0 +84,0 @@ const configuredRule = rule();

@@ -23,3 +23,3 @@ import type { LintRule, LintRuleInitializer } from "./rule.js";

*/
export declare const createLintRuleCollection: <RulesSettings extends Record<string, LintRuleInitializer<never>>>(rules: RulesSettings) => RuleCollectionInitializer<RulesSettings>;
export declare const createLintRuleCollection: <RulesSettings extends Record<string, LintRuleInitializer<never, false>>>(rules: RulesSettings) => RuleCollectionInitializer<RulesSettings>;
export {};
{
"name": "@inlang/core",
"type": "module",
"version": "0.4.1",
"version": "0.4.2",
"publishConfig": {

@@ -25,2 +25,6 @@ "access": "public"

},
"./lint/test-utilities": {
"types": "./dist/lint/test-utilities.d.ts",
"import": "./dist/lint/test-utilities.js"
},
"./query": {

@@ -27,0 +31,0 @@ "types": "./dist/query/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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