@sketch-hq/sketch-assistant-utils
Advanced tools
Comparing version 3.0.1 to 3.0.2
# @sketch-hq/sketch-assistant-utils | ||
## 3.0.2 | ||
### Patch Changes | ||
- b20482b: Ensure testRule function throws when a rule that isn't available in the Assistant is | ||
invoked | ||
- 63350f0: Swap to exernal Assistant types package | ||
- f9d64d8: Update dev dependencies | ||
## 3.0.1 | ||
@@ -14,7 +23,9 @@ | ||
- 0833437: Do not repeat rule and Assistant metadata per violation, instead move the metadata up a level to the result object where it only needs including once | ||
- 0833437: Do not repeat rule and Assistant metadata per violation, instead move the metadata up a | ||
level to the result object where it only needs including once | ||
### Minor Changes | ||
- 0833437: Rules can now optionally declare their platform compatibility, and this is respected by the Assistant runner function | ||
- 0833437: Rules can now optionally declare their platform compatibility, and this is respected by | ||
the Assistant runner function | ||
@@ -24,3 +35,4 @@ ### Patch Changes | ||
- 0833437: Fix `testRule` so that the test config overwrites fully the Assistant's config | ||
- 0833437: Do not strip comments during package compilation, it's useful to retain these so the type comments pop up in intellisense when using the utils in other projects | ||
- 0833437: Do not strip comments during package compilation, it's useful to retain these so the type | ||
comments pop up in intellisense when using the utils in other projects | ||
@@ -27,0 +39,0 @@ ## 2.0.3 |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../types'; | ||
import { Node } from '@sketch-hq/sketch-assistant-types'; | ||
declare function isObject(val: unknown): val is Record<string, unknown>; | ||
@@ -3,0 +3,0 @@ declare function assertNode(val: unknown): asserts val is Node; |
import Ajv from 'ajv'; | ||
import { AssistantConfig, Maybe, RuleConfig, ViolationSeverity, RuleDefinition } from '../types'; | ||
import { AssistantConfig, Maybe, RuleConfig, ViolationSeverity, RuleDefinition } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -14,3 +14,3 @@ * Get rule configuration from an assistant config. | ||
*/ | ||
declare const getRuleOption: (config: AssistantConfig, ruleName: string, optionKey: string) => Maybe<import("../types").RuleOption>; | ||
declare const getRuleOption: (config: AssistantConfig, ruleName: string, optionKey: string) => Maybe<import("@sketch-hq/sketch-assistant-types").RuleOption>; | ||
/** | ||
@@ -17,0 +17,0 @@ * Validate a rule's options in a config object according to the schema defined |
@@ -7,3 +7,3 @@ "use strict"; | ||
const ajv_1 = __importDefault(require("ajv")); | ||
const types_1 = require("../types"); | ||
const sketch_assistant_types_1 = require("@sketch-hq/sketch-assistant-types"); | ||
const rule_option_schemas_1 = require("../rule-option-schemas"); | ||
@@ -59,8 +59,8 @@ /** | ||
switch (severity) { | ||
case types_1.ViolationSeverity.info: | ||
case types_1.ViolationSeverity.warn: | ||
case types_1.ViolationSeverity.error: | ||
case sketch_assistant_types_1.ViolationSeverity.info: | ||
case sketch_assistant_types_1.ViolationSeverity.warn: | ||
case sketch_assistant_types_1.ViolationSeverity.error: | ||
return severity; | ||
default: | ||
return config.defaultSeverity || types_1.ViolationSeverity.error; | ||
return config.defaultSeverity || sketch_assistant_types_1.ViolationSeverity.error; | ||
} | ||
@@ -98,5 +98,5 @@ }; | ||
} | ||
return sanitizedValues.map(value => new RegExp(value)); | ||
return sanitizedValues.map((value) => new RegExp(value)); | ||
}; | ||
exports.getRuleIgnoreNamePathPatterns = getRuleIgnoreNamePathPatterns; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { AssistantDefinition, Assistant, AssistantEnv, Maybe, RuleDefinition, ESModuleInterop } from '../types'; | ||
import { AssistantDefinition, Assistant, AssistantEnv, Maybe, RuleDefinition, ESModuleInterop } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -26,3 +26,3 @@ * Merge assistant definitions together to form a single assistant definition, with a syntax similar | ||
*/ | ||
declare const prepare: (source: import("../types").ValueOrArray<Assistant | ESModuleInterop<Assistant>>, env: AssistantEnv) => Promise<AssistantDefinition>; | ||
declare const prepare: (source: import("@sketch-hq/sketch-assistant-types").ValueOrArray<Assistant | ESModuleInterop<Assistant>>, env: AssistantEnv) => Promise<AssistantDefinition>; | ||
/** | ||
@@ -29,0 +29,0 @@ * Lookup a rule definition by rule name. |
@@ -60,3 +60,3 @@ "use strict"; | ||
}) | ||
.map(f => f(env))); | ||
.map((f) => f(env))); | ||
return assign(...definitions); | ||
@@ -68,4 +68,4 @@ }); | ||
*/ | ||
const getRuleDefinition = (assistant, ruleName) => assistant.rules.find(rule => rule.name === ruleName); | ||
const getRuleDefinition = (assistant, ruleName) => assistant.rules.find((rule) => rule.name === ruleName); | ||
exports.getRuleDefinition = getRuleDefinition; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { NodeCache, NodeCacheIterator, RunOperation } from '../types'; | ||
import { NodeCache, NodeCacheIterator, RunOperation } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Create a Sketch file cache iterator, a function that iterators across objects |
@@ -1,2 +0,2 @@ | ||
import { SketchFile } from '../types'; | ||
import { SketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Given a path to a Sketch file on the file system, this function unzips the |
@@ -1,2 +0,2 @@ | ||
import { GetImageMetadata } from '../types'; | ||
import { GetImageMetadata } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Efficiently access image metadata from a zipped Sketch document. Streams |
@@ -14,3 +14,2 @@ export * from './assert'; | ||
export * from './test-helpers'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -19,3 +19,2 @@ "use strict"; | ||
__export(require("./test-helpers")); | ||
__export(require("./types")); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { Node, FileFormat } from '../types'; | ||
import { Node, FileFormat } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Convert a Sketch file-walking Node to a specific file format object. Use this |
@@ -37,3 +37,3 @@ "use strict"; | ||
algorithm: 'md5', | ||
excludeKeys: key => excludeKeys.includes(key), | ||
excludeKeys: (key) => excludeKeys.includes(key), | ||
}); | ||
@@ -40,0 +40,0 @@ exports.objectHash = objectHash; |
@@ -1,2 +0,2 @@ | ||
import { Maybe, PointerValue, FileFormat } from '../types'; | ||
import { Maybe, PointerValue, FileFormat } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Resolve a JSON Pointer to a value within a SketchFile. |
@@ -1,2 +0,2 @@ | ||
import { RunOperation, ProcessedSketchFile, SketchFile } from '../types'; | ||
import { RunOperation, ProcessedSketchFile, SketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Recursively prepare Sketch document data in preparation for performing a lint |
@@ -1,2 +0,2 @@ | ||
import { RuleOptionSchemaCreator, RuleOptionHelpers } from '../types'; | ||
import { RuleOptionSchemaCreator, RuleOptionHelpers } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Combine multiple rule option schemas into one. We treat _all_ custom options |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const types_1 = require("../types"); | ||
const sketch_assistant_types_1 = require("@sketch-hq/sketch-assistant-types"); | ||
class ReservedRuleOptionNameError extends Error { | ||
@@ -13,3 +13,3 @@ constructor(optionName) { | ||
function assertOptionNameNotReserved(optionName) { | ||
if (Object.values(types_1.ReservedRuleOptionNames).includes(optionName)) { | ||
if (Object.values(sketch_assistant_types_1.ReservedRuleOptionNames).includes(optionName)) { | ||
throw new ReservedRuleOptionNameError(optionName); | ||
@@ -22,6 +22,6 @@ } | ||
*/ | ||
const buildRuleOptionSchema = ops => ({ | ||
const buildRuleOptionSchema = (ops) => ({ | ||
type: 'object', | ||
properties: ops.reduce((acc, props) => (Object.assign(Object.assign({}, acc), props)), {}), | ||
required: ops.map(props => Object.keys(props)).reduce((acc, val) => acc.concat(val), []), | ||
required: ops.map((props) => Object.keys(props)).reduce((acc, val) => acc.concat(val), []), | ||
}); | ||
@@ -32,3 +32,3 @@ exports.buildRuleOptionSchema = buildRuleOptionSchema; | ||
*/ | ||
const numberOption = ops => { | ||
const numberOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -42,3 +42,3 @@ return { | ||
*/ | ||
const integerOption = ops => { | ||
const integerOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -52,3 +52,3 @@ return { | ||
*/ | ||
const stringOption = ops => { | ||
const stringOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -62,3 +62,3 @@ return { | ||
*/ | ||
const booleanOption = ops => { | ||
const booleanOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -77,3 +77,3 @@ return { | ||
*/ | ||
const stringEnumOption = ops => { | ||
const stringEnumOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -94,3 +94,3 @@ return { | ||
*/ | ||
const stringArrayOption = ops => { | ||
const stringArrayOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -110,3 +110,3 @@ return { | ||
*/ | ||
const objectArrayOption = ops => { | ||
const objectArrayOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -113,0 +113,0 @@ return { |
@@ -1,2 +0,2 @@ | ||
import { Violation, RunOperation, RuleUtilsCreator, GetImageMetadata, AssistantDefinition, ProcessedSketchFile } from '../types'; | ||
import { Violation, RunOperation, RuleUtilsCreator, GetImageMetadata, AssistantDefinition, ProcessedSketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Returns a RuleUtilsCreator function, which can be used to build util objects |
@@ -53,11 +53,11 @@ "use strict"; | ||
// Filter out reports involving nodes with ignored `_class` props | ||
.filter(item => { | ||
.filter((item) => { | ||
return item.node ? !classesToIgnore.includes(item.node._class) : true; | ||
}) | ||
// Filter out nodes with ignored name paths | ||
.filter(item => { | ||
.filter((item) => { | ||
if (!item.node || namesToIgnore.length === 0) | ||
return true; | ||
const names = 'name' in item.node ? [item.node.name] : []; | ||
iterateParents(item.node, parent => { | ||
iterateParents(item.node, (parent) => { | ||
if (typeof parent === 'object' && 'name' in parent) { | ||
@@ -68,3 +68,3 @@ names.unshift(parent.name); | ||
const namePath = `/${names.join('/')}`; | ||
return !namesToIgnore.map(regex => regex.test(namePath)).includes(true); | ||
return !namesToIgnore.map((regex) => regex.test(namePath)).includes(true); | ||
}) | ||
@@ -97,3 +97,3 @@ .map((item) => { | ||
const details = result | ||
.map(error => { | ||
.map((error) => { | ||
if (error.dataPath === '') { | ||
@@ -100,0 +100,0 @@ return error.message; |
@@ -1,2 +0,2 @@ | ||
import { AssistantDefinition, ProcessedSketchFile, AssistantEnv, RunOperation, GetImageMetadata, RunResult } from '../types'; | ||
import { AssistantDefinition, ProcessedSketchFile, AssistantEnv, RunOperation, GetImageMetadata, RunResult } from '@sketch-hq/sketch-assistant-types'; | ||
declare class RuleInvocationError extends Error { | ||
@@ -3,0 +3,0 @@ cause: Error; |
@@ -43,4 +43,4 @@ "use strict"; | ||
const activeRules = assistant.rules | ||
.filter(rule => assistant_config_1.isRuleActive(assistant.config, rule.name)) // Rule turned on in config | ||
.filter(rule => (rule.platform ? rule.platform === env.platform : true)); // Rule platform is supported | ||
.filter((rule) => assistant_config_1.isRuleActive(assistant.config, rule.name)) // Rule turned on in config | ||
.filter((rule) => (rule.platform ? rule.platform === env.platform : true)); // Rule platform is supported | ||
const metadata = { | ||
@@ -79,3 +79,3 @@ assistant: { | ||
violations, | ||
errors: Array.from(error).map(error => ({ | ||
errors: Array.from(error).map((error) => ({ | ||
assistantName: error.assistantName, | ||
@@ -82,0 +82,0 @@ ruleName: error.ruleName, |
@@ -1,2 +0,2 @@ | ||
import { FileFormat, Assistant, RuleOptionsCreator, RuleFunction, RuleDefinition, AssistantDefinition, AssistantConfig, ViolationSeverity, RuleConfigGroup, AssistantEnv, RunResult } from '../types'; | ||
import { FileFormat, Assistant, RuleOptionsCreator, RuleFunction, RuleDefinition, AssistantDefinition, AssistantConfig, ViolationSeverity, RuleConfigGroup, AssistantEnv, RunResult } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -47,2 +47,4 @@ * Create a dummy rule definition. | ||
* overwritten by the passed in value to enable testing rules in isolation. | ||
* | ||
* If the rule referenced in the config isn't available in the Assistant an error is thrown. | ||
*/ | ||
@@ -49,0 +51,0 @@ export declare const testRule: (filepath: string, ruleConfig: RuleConfigGroup, assistant: Assistant, env?: AssistantEnv) => Promise<RunResult>; |
@@ -64,2 +64,4 @@ "use strict"; | ||
* overwritten by the passed in value to enable testing rules in isolation. | ||
* | ||
* If the rule referenced in the config isn't available in the Assistant an error is thrown. | ||
*/ | ||
@@ -74,4 +76,9 @@ exports.testRule = (filepath, ruleConfig, assistant, env = { locale: 'en', platform: 'node' }) => __awaiter(void 0, void 0, void 0, function* () { | ||
}; | ||
Object.keys(ruleConfig).forEach((ruleName) => { | ||
if (!assistant_1.getRuleDefinition(assistantDefinition, ruleName)) { | ||
throw new Error(`Rule "${ruleName}" not found on Assistant "${assistantDefinition.name}"`); | ||
} | ||
}); | ||
return yield run_assistant_1.runAssistant(processedFile, assistantDefinition, env, op, get_image_metadata_1.getImageMetadata); | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../types'; | ||
import { Node } from '@sketch-hq/sketch-assistant-types'; | ||
declare function isObject(val: unknown): val is Record<string, unknown>; | ||
@@ -3,0 +3,0 @@ declare function assertNode(val: unknown): asserts val is Node; |
import Ajv from 'ajv'; | ||
import { AssistantConfig, Maybe, RuleConfig, ViolationSeverity, RuleDefinition } from '../types'; | ||
import { AssistantConfig, Maybe, RuleConfig, ViolationSeverity, RuleDefinition } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -14,3 +14,3 @@ * Get rule configuration from an assistant config. | ||
*/ | ||
declare const getRuleOption: (config: AssistantConfig, ruleName: string, optionKey: string) => Maybe<import("../types").RuleOption>; | ||
declare const getRuleOption: (config: AssistantConfig, ruleName: string, optionKey: string) => Maybe<import("@sketch-hq/sketch-assistant-types").RuleOption>; | ||
/** | ||
@@ -17,0 +17,0 @@ * Validate a rule's options in a config object according to the schema defined |
import Ajv from 'ajv'; | ||
import { ViolationSeverity } from '../types'; | ||
import { ViolationSeverity, } from '@sketch-hq/sketch-assistant-types'; | ||
import { helpers, buildRuleOptionSchema } from '../rule-option-schemas'; | ||
@@ -84,5 +84,5 @@ /** | ||
} | ||
return sanitizedValues.map(value => new RegExp(value)); | ||
return sanitizedValues.map((value) => new RegExp(value)); | ||
}; | ||
export { getRuleConfig, getRuleOption, isRuleConfigured, isRuleActive, getRuleSeverity, isRuleConfigValid, getRuleIgnoreClasses, getRuleIgnoreNamePathPatterns, }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { AssistantDefinition, Assistant, AssistantEnv, Maybe, RuleDefinition, ESModuleInterop } from '../types'; | ||
import { AssistantDefinition, Assistant, AssistantEnv, Maybe, RuleDefinition, ESModuleInterop } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -26,3 +26,3 @@ * Merge assistant definitions together to form a single assistant definition, with a syntax similar | ||
*/ | ||
declare const prepare: (source: import("../types").ValueOrArray<Assistant | ESModuleInterop<Assistant>>, env: AssistantEnv) => Promise<AssistantDefinition>; | ||
declare const prepare: (source: import("@sketch-hq/sketch-assistant-types").ValueOrArray<Assistant | ESModuleInterop<Assistant>>, env: AssistantEnv) => Promise<AssistantDefinition>; | ||
/** | ||
@@ -29,0 +29,0 @@ * Lookup a rule definition by rule name. |
@@ -57,3 +57,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}) | ||
.map(f => f(env))); | ||
.map((f) => f(env))); | ||
return assign(...definitions); | ||
@@ -64,4 +64,4 @@ }); | ||
*/ | ||
const getRuleDefinition = (assistant, ruleName) => assistant.rules.find(rule => rule.name === ruleName); | ||
const getRuleDefinition = (assistant, ruleName) => assistant.rules.find((rule) => rule.name === ruleName); | ||
export { prepare, assign, getRuleDefinition }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { NodeCache, NodeCacheIterator, RunOperation } from '../types'; | ||
import { NodeCache, NodeCacheIterator, RunOperation } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Create a Sketch file cache iterator, a function that iterators across objects |
@@ -1,2 +0,2 @@ | ||
import { SketchFile } from '../types'; | ||
import { SketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Given a path to a Sketch file on the file system, this function unzips the |
@@ -1,2 +0,2 @@ | ||
import { GetImageMetadata } from '../types'; | ||
import { GetImageMetadata } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Efficiently access image metadata from a zipped Sketch document. Streams |
@@ -14,3 +14,2 @@ export * from './assert'; | ||
export * from './test-helpers'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -14,3 +14,2 @@ export * from './assert'; | ||
export * from './test-helpers'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { Node, FileFormat } from '../types'; | ||
import { Node, FileFormat } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Convert a Sketch file-walking Node to a specific file format object. Use this |
@@ -31,3 +31,3 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
algorithm: 'md5', | ||
excludeKeys: key => excludeKeys.includes(key), | ||
excludeKeys: (key) => excludeKeys.includes(key), | ||
}); | ||
@@ -34,0 +34,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { Maybe, PointerValue, FileFormat } from '../types'; | ||
import { Maybe, PointerValue, FileFormat } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Resolve a JSON Pointer to a value within a SketchFile. |
@@ -1,2 +0,2 @@ | ||
import { RunOperation, ProcessedSketchFile, SketchFile } from '../types'; | ||
import { RunOperation, ProcessedSketchFile, SketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Recursively prepare Sketch document data in preparation for performing a lint |
@@ -1,2 +0,2 @@ | ||
import { RuleOptionSchemaCreator, RuleOptionHelpers } from '../types'; | ||
import { RuleOptionSchemaCreator, RuleOptionHelpers } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Combine multiple rule option schemas into one. We treat _all_ custom options |
@@ -1,2 +0,2 @@ | ||
import { ReservedRuleOptionNames, } from '../types'; | ||
import { ReservedRuleOptionNames, } from '@sketch-hq/sketch-assistant-types'; | ||
class ReservedRuleOptionNameError extends Error { | ||
@@ -19,6 +19,6 @@ constructor(optionName) { | ||
*/ | ||
const buildRuleOptionSchema = ops => ({ | ||
const buildRuleOptionSchema = (ops) => ({ | ||
type: 'object', | ||
properties: ops.reduce((acc, props) => (Object.assign(Object.assign({}, acc), props)), {}), | ||
required: ops.map(props => Object.keys(props)).reduce((acc, val) => acc.concat(val), []), | ||
required: ops.map((props) => Object.keys(props)).reduce((acc, val) => acc.concat(val), []), | ||
}); | ||
@@ -28,3 +28,3 @@ /** | ||
*/ | ||
const numberOption = ops => { | ||
const numberOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -38,3 +38,3 @@ return { | ||
*/ | ||
const integerOption = ops => { | ||
const integerOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -48,3 +48,3 @@ return { | ||
*/ | ||
const stringOption = ops => { | ||
const stringOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -58,3 +58,3 @@ return { | ||
*/ | ||
const booleanOption = ops => { | ||
const booleanOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -73,3 +73,3 @@ return { | ||
*/ | ||
const stringEnumOption = ops => { | ||
const stringEnumOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -90,3 +90,3 @@ return { | ||
*/ | ||
const stringArrayOption = ops => { | ||
const stringArrayOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -106,3 +106,3 @@ return { | ||
*/ | ||
const objectArrayOption = ops => { | ||
const objectArrayOption = (ops) => { | ||
assertOptionNameNotReserved(ops.name); | ||
@@ -109,0 +109,0 @@ return { |
@@ -1,2 +0,2 @@ | ||
import { Violation, RunOperation, RuleUtilsCreator, GetImageMetadata, AssistantDefinition, ProcessedSketchFile } from '../types'; | ||
import { Violation, RunOperation, RuleUtilsCreator, GetImageMetadata, AssistantDefinition, ProcessedSketchFile } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Returns a RuleUtilsCreator function, which can be used to build util objects |
@@ -41,11 +41,11 @@ import mem from 'mem'; | ||
// Filter out reports involving nodes with ignored `_class` props | ||
.filter(item => { | ||
.filter((item) => { | ||
return item.node ? !classesToIgnore.includes(item.node._class) : true; | ||
}) | ||
// Filter out nodes with ignored name paths | ||
.filter(item => { | ||
.filter((item) => { | ||
if (!item.node || namesToIgnore.length === 0) | ||
return true; | ||
const names = 'name' in item.node ? [item.node.name] : []; | ||
iterateParents(item.node, parent => { | ||
iterateParents(item.node, (parent) => { | ||
if (typeof parent === 'object' && 'name' in parent) { | ||
@@ -56,3 +56,3 @@ names.unshift(parent.name); | ||
const namePath = `/${names.join('/')}`; | ||
return !namesToIgnore.map(regex => regex.test(namePath)).includes(true); | ||
return !namesToIgnore.map((regex) => regex.test(namePath)).includes(true); | ||
}) | ||
@@ -85,3 +85,3 @@ .map((item) => { | ||
const details = result | ||
.map(error => { | ||
.map((error) => { | ||
if (error.dataPath === '') { | ||
@@ -88,0 +88,0 @@ return error.message; |
@@ -1,2 +0,2 @@ | ||
import { AssistantDefinition, ProcessedSketchFile, AssistantEnv, RunOperation, GetImageMetadata, RunResult } from '../types'; | ||
import { AssistantDefinition, ProcessedSketchFile, AssistantEnv, RunOperation, GetImageMetadata, RunResult } from '@sketch-hq/sketch-assistant-types'; | ||
declare class RuleInvocationError extends Error { | ||
@@ -3,0 +3,0 @@ cause: Error; |
@@ -37,4 +37,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const activeRules = assistant.rules | ||
.filter(rule => isRuleActive(assistant.config, rule.name)) // Rule turned on in config | ||
.filter(rule => (rule.platform ? rule.platform === env.platform : true)); // Rule platform is supported | ||
.filter((rule) => isRuleActive(assistant.config, rule.name)) // Rule turned on in config | ||
.filter((rule) => (rule.platform ? rule.platform === env.platform : true)); // Rule platform is supported | ||
const metadata = { | ||
@@ -73,3 +73,3 @@ assistant: { | ||
violations, | ||
errors: Array.from(error).map(error => ({ | ||
errors: Array.from(error).map((error) => ({ | ||
assistantName: error.assistantName, | ||
@@ -76,0 +76,0 @@ ruleName: error.ruleName, |
@@ -1,2 +0,2 @@ | ||
import { FileFormat, Assistant, RuleOptionsCreator, RuleFunction, RuleDefinition, AssistantDefinition, AssistantConfig, ViolationSeverity, RuleConfigGroup, AssistantEnv, RunResult } from '../types'; | ||
import { FileFormat, Assistant, RuleOptionsCreator, RuleFunction, RuleDefinition, AssistantDefinition, AssistantConfig, ViolationSeverity, RuleConfigGroup, AssistantEnv, RunResult } from '@sketch-hq/sketch-assistant-types'; | ||
/** | ||
@@ -47,2 +47,4 @@ * Create a dummy rule definition. | ||
* overwritten by the passed in value to enable testing rules in isolation. | ||
* | ||
* If the rule referenced in the config isn't available in the Assistant an error is thrown. | ||
*/ | ||
@@ -49,0 +51,0 @@ export declare const testRule: (filepath: string, ruleConfig: RuleConfigGroup, assistant: Assistant, env?: AssistantEnv) => Promise<RunResult>; |
@@ -12,3 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { process } from '../process'; | ||
import { prepare } from '../assistant'; | ||
import { prepare, getRuleDefinition } from '../assistant'; | ||
import { runAssistant } from '../run-assistant'; | ||
@@ -58,2 +58,4 @@ import { getImageMetadata } from '../get-image-metadata'; | ||
* overwritten by the passed in value to enable testing rules in isolation. | ||
* | ||
* If the rule referenced in the config isn't available in the Assistant an error is thrown. | ||
*/ | ||
@@ -68,2 +70,7 @@ export const testRule = (filepath, ruleConfig, assistant, env = { locale: 'en', platform: 'node' }) => __awaiter(void 0, void 0, void 0, function* () { | ||
}; | ||
Object.keys(ruleConfig).forEach((ruleName) => { | ||
if (!getRuleDefinition(assistantDefinition, ruleName)) { | ||
throw new Error(`Rule "${ruleName}" not found on Assistant "${assistantDefinition.name}"`); | ||
} | ||
}); | ||
return yield runAssistant(processedFile, assistantDefinition, env, op, getImageMetadata); | ||
@@ -70,0 +77,0 @@ }); |
@@ -5,6 +5,15 @@ MIT License | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
associated documentation files (the "Software"), to deal in the Software without restriction, | ||
including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all copies or substantial | ||
portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES | ||
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
{ | ||
"name": "@sketch-hq/sketch-assistant-utils", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"module": "dist/esm/index", | ||
@@ -30,4 +30,3 @@ "main": "dist/cjs/index", | ||
"@json-schema-spec/json-pointer": "0.1.2", | ||
"@sketch-hq/sketch-file-format-ts": "4.0.2", | ||
"@types/json-schema": "7.0.4", | ||
"@sketch-hq/sketch-assistant-types": "1.0.0", | ||
"ajv": "6.12.0", | ||
@@ -38,24 +37,21 @@ "humps": "2.0.1", | ||
"object-hash": "2.0.3", | ||
"p-map": "3.0.0", | ||
"p-map": "4.0.0", | ||
"probe-image-size": "5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "2.5.2", | ||
"@commitlint/cli": "8.3.5", | ||
"@commitlint/config-conventional": "8.3.4", | ||
"@commitlint/prompt-cli": "8.3.5", | ||
"@changesets/cli": "2.6.2", | ||
"@types/humps": "1.1.3", | ||
"@types/jest": "25.1.3", | ||
"@types/jest": "25.2.1", | ||
"@types/node": "13.7.6", | ||
"@types/object-hash": "1.3.1", | ||
"@typescript-eslint/eslint-plugin": "2.21.0", | ||
"@typescript-eslint/parser": "2.21.0", | ||
"@typescript-eslint/eslint-plugin": "2.27.0", | ||
"@typescript-eslint/parser": "2.27.0", | ||
"eslint": "6.8.0", | ||
"eslint-config-prettier": "6.10.0", | ||
"eslint-plugin-import": "2.20.1", | ||
"jest": "25.1.0", | ||
"prettier": "1.19.1", | ||
"ts-jest": "25.2.1", | ||
"typescript": "3.8.2" | ||
"eslint-config-prettier": "6.10.1", | ||
"eslint-plugin-import": "2.20.2", | ||
"jest": "25.3.0", | ||
"prettier": "2.0.4", | ||
"ts-jest": "25.3.1", | ||
"typescript": "3.8.3" | ||
} | ||
} |
@@ -22,3 +22,4 @@ # sketch-assistant-utils | ||
This section of the readme is related to developing the package. If you just want to consume the package you can safely ignore this. | ||
This section of the readme is related to developing the package. If you just want to consume the | ||
package you can safely ignore this. | ||
@@ -39,13 +40,14 @@ ### Scripts | ||
Try and use the [conventional commits](https://www.conventionalcommits.org/) | ||
convention when writing commit messages. This isn't enforced, but you can use | ||
the `yarn commit` command (in place of `git commit -m "foo"`) to open an | ||
interactive CLI to walk you through generating a properly formatted commit | ||
message. | ||
Try and use the [conventional commits](https://www.conventionalcommits.org/) convention when writing | ||
commit messages. | ||
#### Releases | ||
This repo uses [Atlassian Changesets](https://github.com/atlassian/changesets) to automate the npm release process. Read the docs for more information, but the top-level summary is: | ||
This repo uses [Atlassian Changesets](https://github.com/atlassian/changesets) to automate the npm | ||
release process. Read the docs for more information, but the top-level summary is: | ||
- A GitHub Action maintains a permanently open PR that when merged will publish the package to npm with the latest changes and an automatically determined semver | ||
- If the work you do in a PR should affect the next release, then you need to commit a "changeset" to the repo together with the rest of your code changes - do this by running `yarn changeset`. You'll be asked to provide a change type (major, minor or patch) and a message | ||
- A GitHub Action maintains a permanently open PR that when merged will publish the package to npm | ||
with the latest changes and an automatically determined semver | ||
- If the work you do in a PR should affect the next release, then you need to commit a "changeset" | ||
to the repo together with the rest of your code changes - do this by running `yarn changeset`. | ||
You'll be asked to provide a change type (major, minor or patch) and a message |
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
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
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
9
14
52
169912
116
2277
+ Added@sketch-hq/sketch-assistant-types@1.0.0(transitive)
+ Addedp-map@4.0.0(transitive)
- Removed@types/json-schema@7.0.4
- Removedp-map@3.0.0(transitive)
Updatedp-map@4.0.0