Code Monkey home page Code Monkey logo

linter's Introduction

Sass

@SassCSS on Twitter    stackoverflow    Gitter

Sass makes CSS fun again. Sass is an extension of CSS, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a plugin for your build system.

$font-stack: Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}

@mixin border-radius($radius) {
  -webkit-border-radius: $radius;
     -moz-border-radius: $radius;
      -ms-border-radius: $radius;
          border-radius: $radius;
}

nav {
  ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  li { @include border-radius(10px); }

  a {
    display: block;
    padding: 6px 12px;
    text-decoration: none;
  }
}

Install Sass

You can install Sass on Windows, Mac, or Linux by downloading the package for your operating system from GitHub and adding it to your PATH. That's all—there are no external dependencies and nothing else you need to install.

If you use Node.js, you can also install Sass using npm by running

npm install -g sass

However, please note that this will install the pure JavaScript implementation of Sass, which runs somewhat slower than the other options listed here. But it has the same interface, so it'll be easy to swap in another implementation later if you need a bit more speed!

See the Sass website for more ways to install Sass.

Once you have Sass installed, you can run the sass executable to compile .sass and .scss files to .css files. For example:

sass source/stylesheets/index.scss build/stylesheets/index.css

Learn Sass

Check out the Sass website for a guide on how to learn Sass!

This Repository

This repository isn't an implementation of Sass. Those live in sass/dart-sass and sass/libsass. Instead, it contains:

  • spec/, which contains specifications for language features.
  • proposal/, which contains in-progress proposals for changes to the language.
  • accepted/, which contains proposals that have been accepted and are either implemented or in the process of being implemented.

Note that this doesn't contain a full specification of Sass. Instead, feature specifications are written as needed when a new feature is being designed or when an implementor needs additional clarity about how something is supposed to work. This means many of the specs in spec/ only cover small portions of the features in question.

Versioning Policy

The proposals in this repository are versioned, to make it easy to track changes over time and to refer to older versions. Every version has a Git tag of the form proposal.<name>.draft-<version>. A new version should be created for each batch of changes.

Every version has a major version, and they may have a minor version as well (indicated <major>.<minor>). The minor version should be incremented for changes that don't affect the intended semantics of the proposal; otherwise, the major version should be incremented.

linter's People

Contributors

asottile avatar nschonni avatar srawlins avatar

Stargazers

 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linter's Issues

Add a lint rule for unnecessary parentheses in conditionals

Sometimes users who are familiar with other languages forget that Sass doesn't need parentheses around its conditionals (as in, @if (...) {, or @else if (...) {, or @while (...) {). The linter should suggest that these parentheses be removed.

Add a lint for non-idiomatic identifier names

Sass allows either underscores or hyphens to be used interchangeably as identifier separators, but hyphens are preferred as they match CSS's own naming conventions. We should have a lint for any Sass identifier (variable, mixin, function, or placeholder name) that complains about underscores and suggests using hyphens instead.

Add a lint for named colors as map keys

A mistake we see occasionally is users using unquoted strings as map keys, having one of those keys be named something like blue, and getting confused later on when that key compiles to #00f instead. We should add a lint rule to help out with this.

The most conservative way to do this is probably to warn the user when a map:

  • contains an unquoted string key,
  • contains a color name key, and
  • contains only unquoted string or color name keys.

Less conservatively, we could also warn about maps that have keys of mixed type in general or maps with any unquoted string keys, although this risks having more false positives.

Add a lint for color adjustment functions

A handful of built-in Sass functions adjust colors in a way that subtly fails to meet user expectations. They add/subtract numbers to/from the colors' properties rather than fluidly scaling them towards the max/min value, which can clip colors to the maximum or minimum values. For example, darken($color, 30%) will return black for every color with lightness 30% or lower.

The scale-color() function behaves much more intuitively. It fluidly scales properties, so that for example scale-color($color, $lightness: -30%) will always return a darker color but will never return black unless the input is already black. Unfortunately, the other functions are older and have more obvious names, so users tend to gravitate towards them. A lint would help steer people away.

The functions that should have this lint are saturate(), desaturate(), darken(), lighten(), opacify(), fade-in(), transparentize(), and fade-out().

Add a lint for unnecessary calls to quote() and unquote()

The quote() function is never necessary when the argument is already a quoted string, and the unquote() function is never necessary immediately within interpolation. I've seen these mistakes appear in the wild, so it would be good to add lints for them.

Implement "Nesting Depth" lint rule

Need to implement a lint rule that reports style rules that are too deep, in terms of Sass nesting (not selector specificity):

p.foo {
  .bar {
    .error {
      .severe { // LINT
        color: red;
      }
    }
  }
}

This is similar to scss-lint's NestingDepth.

Support Dart SDK >= 2.0.0

I tried running the linter, but it fails on my machine:

~/github/linter/$ pub get
Resolving dependencies... 
The current Dart SDK version is 2.1.0.
Because sass_linter requires SDK version >=1.22.0 <2.0.0, version solving failed.

I wonder, maybe this needs just a config change in pubspec.yaml?

(FWIW, I tried this, and then it says: Because sass_linter depends on test >=0.12.0-beta.3 <1.3.0 which requires SDK version >=1.8.0 <2.0.0-∞, version solving failed. - so it looks like there's more work to be done.)

Add a lint rule for unquoted strings in map keys

It's generally a bad practice to use unquoted strings as map keys. Some tokens (like green) parse as colors rather than strings, which means that if the keys are used in selector names, they won't necessarily emit as text (for example, green is emitted as #0f0 in compressed mode). It would be good to have a lint that encourages users to quote their map keys.

Add a lint for using @each with maps properly

A pattern I see occasionally is:

@each $key in map-keys($map) {
  $value: map-get($map, $key);
  // ...
}

This is an unnecessarily verbose way of writing:

@each $key, $value in $map {
  // ...
}

There are also some legitimate cases where only the key is used, so maybe it's a good idea to look for the pattern map-get($map, $key) in the loop body before raising the lint?

Add a lint rule for != null and == null

Because null in Sass is falsey, users should treat it as a boolean rather than explicitly checking for it. For example, @if index(...) { ... } is preferable to @if index(...) != null { ... }.

Add a lint rule for fake dimensions

Users who don't fully understand how Sass's unit arithmetic works will often write code like #{$var}px in an attempt to add units to a number. However, this produces an unquoted string rather than an actual numeric value, which means it won't work with arithmetic or Sass functions. It would be good to provide a lint that suggests they write $var * 1px instead and that links to documentation on how number arithmetic works.

Support the indented syntax

Right now, the linter only parses files that use the SCSS syntax. It should detect if files have the .scss syntax, and use the indented syntax parser for them. Both syntaxes produce the same AST, so it should be relatively easy to support both.

Add a lint rule for standalone script interpolation

Because interpolation is necessary to include SassScript values in many contexts, users sometimes accidentally use it in SassScript expressions themselves. For example, see this line from Angular's Material Design components. Not only is this unnecessary, it coerces the result of the expression to an unquoted string, which may make it fail with further mathematical operations down the line.

There should be a lint for this. Specifically, if an interpolated identifier that's just a single interpolation with no other text is encountered, the linter should suggest the user replace it with the value of the expression.

Implement "Import Path" lint rule

Need to implement a lint rule that reports import paths that do not fit the brief, human-readable style. Namely, underscores and file suffixes are unnecessary.

@import "partials/_colors.scss";  // LINT
@import "partials/_colors";       // LINT
@import "partials/colors.scss";   // LINT

@import "partials/colors";        // OK

This is similar to scss-lint's ImportPath.

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.