This package has moved to https://github.com/sketch-hq/sketch-assistants.
sketch-hq / sketch-assistant-utils Goto Github PK
View Code? Open in Web Editor NEWUtility functions for running Sketch Assistants
License: MIT License
Utility functions for running Sketch Assistants
License: MIT License
This package has moved to https://github.com/sketch-hq/sketch-assistants.
The current design groups violations by rule title, and requires more descriptive rule titles that interpolate config values into the copy. E.g.
The rule title here is in the format,
Minimum height should be {minimumHeight}px
Where the minimumHeight
value is presumably comes from the current Assistant's config object.
Currently the Assistant types and utils don't support this.
Proposal here is to update the RuleDefinition type so that it's title
can either be a string
(as now), or optionally a function that returns a string and takes the current Assistant config as an argument.
title: string | (ruleConfig: RuleConfig) => string
This will allow rule definitions to flexibly return strings based on their own config values. Additionally if the rule definition uses some i18n system this can be used to generate the string too.
Rule title
values defined as functions would need to be invoked before returning to Sketch, or displayed elsewhere.
Run through the current core rule titles and re-write them to be more in the style indicated by the designs, e.g. Minimum height should be {minimumHeight}px etc.
A tone-of-voice review, and after that internationalisation.
Add option validation logic in rules, that throws an error if an option is in the wrong format. We should be able to do this automatically using the option schema when a rule requests it's options.
While processing a Sketch file in sketch-lint-core we augment each object with a JSON Pointer. It will also prove useful to augment it with a layer name path too, e.g. /Page 1/Artboard Foo/Rectangle
.
Rules may frequently wanting to adjust logic based on the hierarchy of layer names they find themselves in. We'll also need this feature when we come to ignoring violations based on layer names.
Revisit config level ignore options based on this discussion #24 (comment)
Probably this means removing support for them at this stage. Ignoring things via the Sketch UI should be the focus initially.
We'll introduce a convention that all lint ruleset packages are named with a prefix sketch-lint-ruleset-
, so will name the new package sketch-lint-ruleset-core
.
This is so Assistants don't have to add this utils repo as a dependency, and run the risk of swelling their bundle size, when they only need the types.
When TypeScript or Babel transpiles a ESModule to CommonJS it uses a technique called "ES Module interoperability" to make the module CommonJS compatible.
So this ES Module syntax,
const foo = {}
export default foo
Ends up looking like this CommonJS syntax,
const foo = {}
module.exports = {
__esModule: true,
default: foo
}
This change ensures that when we are working with assistant packages (specifically initializing them before a lint run) we handle the case where some of them might have been transpiled from ES Module syntax to CommonJS (indeed our official Assistants will mostly look like this, since we generally want to use ES Modules where possible).
Give rule functions a utility for iterate back through the parents of any given node. This will allow rules to easily branch lint logic based on where nodes find themselves in the tree.
Name paths to match will now always start with a slash. This doesn't change anything when matching a portion of the name path, but will be useful if users want to match from the name path root.
Also as part of this I'm renaming the option to the more explicit/descriptive ignoreNamePathPatterns
.
Example,
{
"borders-no-disabled": {
"active": true,
"ignoreNamePathPatterns": [
"/Page 2/Rectangle"
]
}
}
Add optional ignoreClasses
and ignoreNames
rule config options.
ignoreClasses
This option allows config authors to suppress violations from rules using an array of file format _class
values.
E.g. with the rule config below violations from pages are filtered out of the final result.
{
"groups-max-layers": {
"active": true,
"maxLayers": 10,
"ignoreClasses": ["page"]
}
}
ignoreNames
This option allows config authors to supply an array of regex patterns that when matched with a node's "name path" would suppress violations for that rule.
The "name path" for any given node in the file data is defined as a /
separated string comprised of all the name values leading up to and including the node, from the document root. If a node's name already contains /
characters, as is a blessed convention in Sketch, then those are just concatenated into the final path.
Examples name paths:
/Page 1/Rectangle
/Symbols/UI/Buttons/Round
/Symbols/UI/Inputs/Password
/Symbols/UI/Media/Controls
E.g. The rule config below would suppress violations for any symbols in the UI/Inputs
group
{
"groups-max-layers": {
"active": true,
"maxLayers": 10,
"ignoreNames": ["UI\/Inputs"]
}
}
Begin some documentation for sketch-lint-core
APIs and functionality. Specifically rule functions and their utilities.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.