GithubHelp home page GithubHelp logo

sketch-hq / sketch-assistant-utils Goto Github PK

View Code? Open in Web Editor NEW
0.0 41.0 0.0 62.63 MB

Utility functions for running Sketch Assistants

License: MIT License

JavaScript 0.21% TypeScript 99.79%
sketch sketch-lint linting

sketch-assistant-utils's Introduction

sketch-assistant-utils's People

Contributors

jedrichards avatar github-actions[bot] avatar

Watchers

Michael Dominic K. avatar Bruno Bakundwa avatar Jelle De Laender avatar Klaas Pieter Annema avatar Rob Mooney avatar Philipp Seibel avatar Clément Uster avatar Diego Souza avatar Curtis Hard avatar Matthias Keiser avatar Keir Ansell avatar Nestor Lafon-Gracia avatar Janik Baumgartner avatar Sean Reilly avatar Hugo Dias avatar Adrian Gruntkowski avatar Daniel S. Matilla avatar James Cloos avatar Muhammad Yusuf avatar Francesco Bertocci avatar Oliver Michalak avatar Tiago Oliveira avatar Christopher Downer avatar Ludovico Rossi avatar Luigi Parpinel avatar Markus Piipari avatar Evan Smith avatar Ovidiu Donciu avatar Oscar Forner Martinez avatar Sandra  avatar Rúben Almeida avatar  avatar John Maguire avatar Jorge Fernández avatar Gavin MacLean avatar Thiago Nogueira avatar Dorian Amouroux avatar Juli Arnalot avatar Andrei Matei avatar Michael G. Tascu avatar  avatar

sketch-assistant-utils's Issues

Evolve core rule titles

Step 1

The current design groups violations by rule title, and requires more descriptive rule titles that interpolate config values into the copy. E.g.

Screenshot 2020-04-16 at 17 46 24

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.

Step 2

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.

Future steps...

A tone-of-voice review, and after that internationalisation.

Full rule option validation

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.

Augment nodes with a layer name path string

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.

Extract ruleset into its own package

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.

Handle Assistants packages exported as transpiled ES Modules

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).

Add iterate parents util

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.

Refactor core utils for assistants

  • Refactor for assistant architectural changes
  • Ensure assistants can be initialized lazily
  • Throw an error if reserved names are used for rule options
  • Assistant extension mechanism

Ensure ignoreName path patterns begin with a forward slash

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"
    ]
  }
}

Config level ignores

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"]
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.