css-dont-reassign

0.9.0 • Public • Published

css-dont-reassign

A linter to help stop you reassigning your CSS selectors

Motivation

This module has been heavily inspired by Immutable CSS and Functional Programming, CSS, and your sanity. Both ideas describe a style of writing CSS in which your (specified) classes should never be overwritten - go and read them though, as they describe it better than here!

Installation

$ npm i --save css-dont-reassign

Usage

var dontReassign = require('css-dont-reassign');
 
dontReassign(pathToCss /*, options */)
    .then(function (result) { 
        console.log(result.toString());
    });

dontReassign() takes two arguments, pathToCss should be a fully qualified path to a css file. options is an optional argument, covered in detail below.

Options

classMatch (optional)

(string|regex)

This will allow you to specify a matching pattern for your selectors. E.g .util-, will only match selectors prefixed with .util-. This is described in the Enforcing Immutability section on CSS Wizadry.

Result

Result is an array of issues, and has a toString method.

Issue object

{
    selector: String,
    line: Object, // { line: Number, column: Number }
    from: String
    rule: Rule
}

selector

The selector that was defined or mutated.

line

An object containing the line and column of the selector definition.

from

The file path.

rule

The raw postcss class.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.9.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.9.0
    1

Package Sidebar

Install

npm i css-dont-reassign

Weekly Downloads

1

Version

0.9.0

License

ISC

Last publish

Collaborators

  • willmonk