Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Apply Stylint to the codebase #681

Merged
merged 7 commits into from
Jul 17, 2017
Merged

Apply Stylint to the codebase #681

merged 7 commits into from
Jul 17, 2017

Conversation

orta
Copy link
Contributor

@orta orta commented Jul 13, 2017

screen shot 2017-07-13 at 17 06 06

Currently just gives us inline warnings. All auto-fixing tools aren't quite there yet, so I've not added them, apart from recommending the extension.

WIP because it still fails, due to prettier cropping template strings into a single line occasionally and stylinbt doesn't like that.

Skip new tests

@ArtsyOpenSource
Copy link

ArtsyOpenSource commented Jul 13, 2017

Warnings
⚠️

Missing Test Files:

  • src/lib/Components/Storybooks/__tests__/Styles-tests.tsx

If these files are supposed to not exist, please update your PR body to include "Skip New Tests".

⚠️

New dependencies added: stylelint, stylelint-config-standard and stylelint-processor-styled-components.

stylelint

Author: Unknown

Description: A mighty, modern CSS linter.

Homepage: https://stylelint.io

Createdover 2 years ago
Last Updated1 day ago
LicenseMIT
Maintainers5
Releases112
Direct Dependenciesautoprefixer, balanced-match, chalk, cosmiconfig, debug, execall, file-entry-cache, get-stdin, globby, globjoin, html-tags, ignore, imurmurhash, known-css-properties, lodash, log-symbols, mathml-tag-names, meow, micromatch, normalize-selector, pify, postcss, postcss-less, postcss-media-query-parser, postcss-reporter, postcss-resolve-nested-selector, postcss-scss, postcss-selector-parser, postcss-value-parser, resolve-from, specificity, string-width, style-search, sugarss, svg-tags and table
Keywordscss, less, scss, sugarss, lint, linter and stylelint
README # stylelint

NPM version Build Status Build status NPM Downloads Bountysource

A mighty, modern CSS linter and fixer that helps you avoid errors and enforce consistent conventions in your stylesheets.

Features

  • Over one hundred and fifty rules: Including those that:
    • Catch errors: e.g. invalid hex colors, duplicate selectors and overriding shorthand properties.
    • Limit language features: e.g. vendor prefixes, patterns for selectors and specific units, properties, functions and at-rules.
    • Enforce stylistic conventions: e.g. the whitespace around the colon in declarations and the number of empty lines between rules.
  • Support for the latest CSS syntax: Including custom properties, calc() and nesting.
  • Understands CSS-like syntaxes: The linter is powered by PostCSS, so it understands any syntax that PostCSS can parse, including SCSS, SugarSS, and Less.
  • Completely unopinionated: Only enable the rules you want, and configure them with options that tailor the linter to your needs.
  • Support for plugins: It's easy to create your own rules and add them to the linter.
  • Automatically fixes some stylistic warnings: Save time by having stylelint fix your code with this experimental feature.
  • Shareable configs: If you don't want to craft your own config, you can extend a shareable config.
  • Options validator: So that you can be confident that your config is valid.
  • Well tested: Over ten thousand tests cover the internals and rules.
  • Growing community: Used by Facebook, Github, Wikimedia, GSA, and WordPress among others.

Example output

Example

Getting started

With stylelint, it's easy to start linting your CSS:

  1. Decide how you want to use stylelint:
  2. Create your configuration object by either extending a shared config or crafting your own:
    • To extend a shared config, we suggest using either stylelint-config-standard or stylelint-config-recommended. The recommended config turns on just the possible error rules. The standard config builds on top of the recommened config by additionally turning on over 60 of stylelint's stylistic rules with sensible defaults. You can always override specific rules after extending either config. When using either config, you'll likely want to add (and configure to your specific needs) some of the rules that limit language features. We update the configs with each new release of stylelint, so it's easy to stay up to date. Alternately, you can search for a community config and extend that instead.
    • To craft your own config, first learn about how rules are named and how they work together, then either:
      • Start small and only learn about the rules you want to turn on and enforce. All of the rules are off by default, and so you can start small, growing your config over time as you have a chance to explore more of the rules.
      • Or copy-paste this example configuration, which lists all of stylelint's rules and their primary options. Then you can edit the options of each rule to your liking, and remove (or turn off with null) the rules that you don't care to enforce.
  3. Lint!

Guides

You'll find more detailed information on using stylelint and tailoring it to your needs in our guides:

  • User guide - Usage, configuration, FAQ and complementary tools.
  • Developer guide - Contributing to stylelint and writing your own plugins & formatters.

Need help?

If you're looking for help or have a support question, then check out our FAQ first. If the answer to your problem isn't there, then go to stackoverflow. stackoverflow is a huge Question and Answer community, and tagging your post there with "stylelint" will catch the stylelint team's attention.

If you think you've found a bug or if you have feature request, then create a new GitHub issue. Be sure to follow the issue template, answering each question, as this helps us greatly in understanding your problem or request.

Upgrading? Please read our CHANGELOG to learn what changes to expect in the latest version, whether that's new features, bug fixes, renamed rules, or whatever else.

Help out

There is always a lot of work to do, and already well over 150 rules to maintain. So please help out in any way that you can:

Interested in the project vision? Please read our VISION document.

Semantic Versioning Policy

stylelint follows semantic versioning. However, due to the nature of stylelint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, based on ESLint's semantic versioning policy we've defined the following semantic versioning policy for stylelint:

  • Patch release (intended to not break your lint build)

    • A bug fix in a rule that results in stylelint reporting fewer errors.
    • A bug fix to the CLI or core (including formatters).
    • Improvements to documentation.
    • Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
    • Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
  • Minor release (might break your lint build)

    • A bug fix in a rule that results in stylelint reporting more errors.
    • A new rule is created.
    • A new option to an existing rule that does not result in stylelint reporting more errors by default.
    • An existing rule is deprecated.
    • A new CLI capability is created.
    • New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
    • A new formatter is created.
  • Major release (likely to break your lint build)

    • A change in the documented behaviour of an existing rule results in stylelint reporting more errors by default.
    • An existing rule is removed.
    • An existing formatter is removed.
    • Part of the public API is removed or changed in an incompatible way.

According to our policy, any minor update may report more errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (~) in package.json e.g. "stylelint": "~7.2.0" to guarantee the results of your builds.

License

yarn why stylelint output

  • Has been hoisted to "stylelint"
  • This module exists because it's specified in "devDependencies".
  • Disk size without dependencies: "3.41MB"
  • Disk size with unique dependencies: "12.28MB"
  • Disk size with transitive dependencies: "31.57MB"
  • Number of shared dependencies: 117

stylelint-config-standard

Author: stylelint

Description: Standard shareable config for stylelint

Homepage: https://github.com/stylelint/stylelint-config-standard#readme

Createdover 1 year ago
Last Updated1 day ago
LicenseMIT
Maintainers3
Releases23
Direct Dependenciesstylelint-config-recommended
Keywordsstylelint, stylelint-config and standard
This README is too long to show.
yarn why stylelint-config-standard output

  • Has been hoisted to "stylelint-config-standard"
  • This module exists because it's specified in "devDependencies".
  • Disk size without dependencies: "48kB"
  • Disk size with unique dependencies: "48kB"
  • Disk size with transitive dependencies: "48kB"
  • Number of shared dependencies: 0

Generated by 🚫 dangerJS

@orta orta changed the title [WIP] Apply Stylint to the codebase Apply Stylint to the codebase Jul 14, 2017
@orta
Copy link
Contributor Author

orta commented Jul 14, 2017

screen shot 2017-07-14 at 12 49 13

Alright, this is now good to go.

This PR adds a command yarn stylelint-project which will verify, I'm not running this on CI because we cannot do an auto-fix, you'll get errors in your editor inline, so that's probably enough until it becomes an issue.

@l2succes
Copy link
Contributor

Nice! I had stylelint setup in a branch as well but I couldn't figure out the auto-fix part. But yours is more useful because we get error highlighting in the editor.

Let's merge once it's green

@orta
Copy link
Contributor Author

orta commented Jul 14, 2017

Great - these fails are legit

@alloy
Copy link
Contributor

alloy commented Jul 14, 2017

Noice 🌟

"extends": "stylelint-config-standard",
"syntax": "scss",
"rules": {
"property-no-unknown": [true, { "ignoreProperties": ["resize-mode"] }],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add comments in this file, so these are RN specific keys

"rules": {
"property-no-unknown": [true, { "ignoreProperties": ["resize-mode"] }],
"block-opening-brace-space-after": null,
"block-closing-brace-space-before": null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are because prettier will truncate single lined CSS elements into a single LOC

"property-no-unknown": [true, { "ignoreProperties": ["resize-mode"] }],
"block-opening-brace-space-after": null,
"block-closing-brace-space-before": null,
"declaration-block-no-redundant-longhand-properties": null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RN supports different rules for CSS occasionally, following this linter will get unexpected fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules are about things like margin: 20px 10px 30px which corresponds to 20px 10px 30px 10px in browsers, but not in RN

@orta
Copy link
Contributor Author

orta commented Jul 17, 2017

OK, this is good to go

@orta orta merged commit 515858d into master Jul 17, 2017
@alloy alloy deleted the style branch July 17, 2017 18:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants