GithubHelp home page GithubHelp logo

sketch-hq / sketch-assistant-core-rules Goto Github PK

View Code? Open in Web Editor NEW
1.0 41.0 1.0 89.84 MB

Sketch Assistant containing the official core rules

License: MIT License

JavaScript 0.39% TypeScript 99.61%
sketch sketch-assistant linting linting-rules

sketch-assistant-core-rules's Introduction

sketch-assistant-core-rules's People

Contributors

bohemianjenkins avatar bomberstudios avatar christianklotz avatar github-actions[bot] avatar jedrichards avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jedrichards

sketch-assistant-core-rules's Issues

Add suggestion/static message rule

Summary

We've been discussing various scenarios for assistants that don't strictly check a document for validity but rather offer a list of suggestions or a checklist. This could be something particularly useful for team onboarding and general workflow conventions.

More sophisticate variants of this could be the display of usage instructions when certain design system components are being used within a design but this is out of scope of this rule.

Options

messages

Set a list of messages with custom strings, e.g.

  • Save to Sketch Cloud
  • Run copy past the marketing team

severity

For discussion, should each item have its own severity or do we just go with the rule-wide severity? Is this part of the messages option?

Rule name

Not sure what would make a good rule name, report, report-always, report-custom-message, report-message-custom, @jedrichards?

Investigate layers-subpixel-positioning feedback with strange layer coordinates

See feeback from https://www.notion.so/sketchapp/Feedback-highlights-186f5de5a97b4b82bddaf4deaf3da339

Seeing violations for Unexpected subpixel positioning of 0.99999999999775 – a number Sketch can not display. He's not sure how this originally happened, as it's an old file (he thinks he combined some uneven shapes and then moved them around), but either way, this is either a Sketch problem or an Assistant problem. If Sketch says the circle sits on X=1, seeing a violation in Assitantant about the layer being off the pixel grid feels strange.

Also seeing a few violations for Unexpected subpixel positioning but everything seems good looking at the coordinates. Moving the layer up and down with the mouse to the exact same coordinates seems to fix the issue.

This seems like a Sketch problem, but need to decide if this is something we can handle in the rule, or whether it's not the rule's concern ...

Add detect similar groups rule

This would be a rule that detected groups with similar contents, so a suggestion could be made to abstract them into a symbol. Possible rule name groups-detect-similar? Or groups-prefer-symbols?

Group similarity would be based on creating a consistent "fingerprint" for each group, initially comprised of the follow metrics:

  • Number of child layers
  • Values and order of layer types in child layers
  • Values and order of layer names in child layers

We can revisit the way we generate the fingerprint based on feedback.

One approach could be to create a hash from the dataset defined above, then we would only need to compare hashes when looping over groups.

Rule configuration could include a maxIdentical value, for example the rule could tolerate 2 similar groups before raising any violations.

Add "no dirty" core rules

"No dirty" rules would check for layer styles that have diverged from their associated shared style.

Two new rules could implement this behaviour:

  • text-styles-no-dirty
  • layer-styles-no-dirty

Inspiration for these rules comes from this community plugin https://github.com/KevinGutowski/FindDirtyStyles

Approach

I haven't thought through the approach fully yet but it's likely to involve:

  • For each layer/text style in the document
    • If it has an associated shared style
      • Compare the layer style with the shared style, and if they're different raise a violation (when comparing styles a possible approach is to compare their hash like we're already doing here)

Refactor core ruleset for assistants

sketch-lint-ruleset-core needs to become a "rules only" assistant, perhaps called something like sketch-assistant-core-rules.

  • Update to refactored core module, making changes where necessarily for new types
  • Update to use new lazy initialization for i18n
  • Rename repo and publish as private package using changesets

Can't find module '../../../test-helpers'

Hi!

I am trying this wonderful package but I can't get to import rules from this repo to the template, I don't really know (I was looking the documentation but I couldn't find anything about that)

When I run yarn test --watch with some of the rules imported this message appear.

FAIL  src/rules/artboards-grid/__tests__/index.ts
  ● Test suite failed to run

    src/rules/artboards-grid/__tests__/index.ts:1:26 - error TS2307: Cannot find module '../../../test-helpers'.

    1 import { testRule } from '../../../test-helpers'

Probably I am doing something wrong xD

Thanks!

Move Core Rules Assistant into the monorepo

QA

  1. Git clone [email protected]:sketch-hq/sketch-assistants.git
  2. Checkout the PR branch git checkout feature/add-core-rules
  3. In the repo root run yarn
  4. Still in the repo root run yarn build

For the three assistants tidy, reuse-suggestions and naming-conventions ensure that they can still be packaged and added to Sketch locally, and they generate the expected violations.

E.g.

cd assistants/tidy
yarn package-tarball
# Then "Add from Disk" in Sketch Experimental

Implement an `images-no-undersized` rule

Implement a rule that works similarly to images-no-outsized, but instead of checking for over sized images, check for undersized images like to produce poor results in exported graphics.

Style equality method

Objective

Move the style comparison methods into the rule utils object. These methods can keep the existing hash-based approach. These methods must cover our existing style comparison cases.

Motivation

The style comparison is being hand-rolled and repeated in a couple of rules:

  • layer-styles-no-dirty
  • layer-styles-prefer-shared
  • text-styles-no-dirty
  • text-styles-prefer-shared
  • 2 of the 3 library rules

It differs only slightly between them (e.g. text comparisons take into consideration the textStyle attribute).

This poses an opportunity to refactor these parts of the code and perhaps even speed them up.

Implement initial ruleset umbrella ☂️

Umbrella issue for implementing initial ruleset. It may be sensible to firm up the rule architecture a bit before diving into these (e.g. sketch-hq/sketch-lint#1 and sketch-hq/sketch-document#9)

  • images-no-outsized #13
  • artboards-layout #12
  • artboards-grid #11
  • borders-no-disabled #10
  • groups-no-empty #9
  • layers-no-subpixel-positioning #8
  • styles-no-unused #7
  • groups-no-redundant #6
  • styles-no-duplicate #5
  • layer-names-pattern-allowed #4
  • layers-no-hidden #3
  • groups-max-layers #2
  • symbols-no-unused #1

Tidy up rule tests

Move Sketch file fixtures near the tests they are used in, delete "Does not generate false negatives" tests (not useful), add more fixtures testing more cases

Add "prefer library" rules

Disallow the usage of any document-local symbols, shared styles or shared text styles, preferring instead for these to come from libraries.

Define a rule option libraries which is an array of whitelisted libraries to act as sources. If the libraries array is empty then any library can be used as source. Investigate whether to use library names or ids in this option array.

Implement as three separate rules:

  • symbols-prefer-library
  • layer-styles-prefer-library
  • text-styles-prefer-library

Ignore styles in "combined shapes" when checking layer styles in multiple rules

From https://www.notion.so/sketchapp/Feedback-31-March-3-April-e8faf52704804db7b33fa3252eba2aae

I have a combined shape that has a shared style applied. However, for all shapes inside this combined shape, I'm getting a violation Expected no identical layer styles in the document, but found 12 matching this layer's style. Consider a shared style instead – this must be a mistake, right? Assistant should not consider the shapes inside a combined shape as individual "layers".

Still having the same issue as reported before, about combined shapes. It's the same issue as Janik but related to Unexpected disabled border on layer style

So it sounds like we have multiple rules that shouldn't be raising violations about styles inside combined shapes.

Complete "no-disabled" rules

Using borders-no-disabled as a guide Implement the following rules:

  • fills-no-disabled
  • inner-shadows-no-disabled
  • shadows-no-disabled

Update the `groups-max-layers` rule

On the groups-max-layers rule:

  1. change the option name from skipClasses to ignore
  2. clarify plural usage (either implement plural support or change the doc/option to specify which names are valid on the array)
  3. report an error when the skipClasses array includes invalid/unsupported class values

Currently the documentation says:

image

Implement a `layers-no-loose` rule

Layers outside of artboards don't show up on Cloud, therefore any layer (including group layers) outside of artboards should raise a violation.

Could a simple approach be to loop over layers that are immediate children of page objects, and check that they are all artboards?

Rework layer name pattern rules

Remove the following rules:

  • layer-names-patterns-allowed
  • layer-names-patterns-disallowed

Replace with rules more focussed on specific layer types:

  • layer-name-pattern-pages
  • layer-name-pattern-artboards
  • layer-name-pattern-symbol-instances
  • layer-name-pattern-symbol-masters
  • layer-name-pattern-groups
  • layer-name-pattern-text
  • layer-name-pattern-shape
  • layer-name-pattern-bitmap

Discussion

  • The allowed and disallowed pattern lists could be moved to become rule options, rather than needing two rules for each layer type
  • Should probably generate some helper functions for generating these rules, since they only differ by the type of layer they look at

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.