• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    CSS
  • Created about 9 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Warn developers about improper selector usage

Nudge

Give developers a gentle push in the right direction.

Nudge is an opinionated, ITCSS-compatible library that detects misuse of certain CSS selectors, and gives developers a subtle nudge to fix them. Mistakes and incorrect usage get highlighted in the UI.

Screenshot showing a simple example of Nudge at work

Installation

$ bower install --save-dev nudgecss

Or:

$ npm install --save-dev nudgecss

Disclaimers and Notices

  1. This is not an active OSS project. Please feel free to use Nudge in your projects, but be aware that this repository exists mainly for me and my clients to use in our work. It’s opinionated, has limited scope, and is not actively seeking contributions. If do have something you feel is a worthy addition within this scope, open an issue.
  2. This is crude. Very crude. The CSS in Nudge is actively bad. It’s circumstantial at best. Nudge is intended to be a very loose, high-level linter, and probably will miss things or give false positives. I’m okay with that—I just want Nudge to be a quick ’n’ dirty, cheap ’n’ cheerful first pass over the UI. For what it needs to do, Nudge is GoodEnough™ for now. More strict and stringent tools should be used if that’s what you require.
  3. Remove Nudge from production. Nudge will fill your stylesheet full of crap: please make sure you remove Nudge before putting any CSS live. This will help performance, but will also ensure that your users never see any errors or breakages that your developers have missed.

Usage

Using Nudge is relatively simple. For more in-depth information and documentation, please see the comments in the relevant files.

Including in your project

  • @import _tools.nudge.scss into your Tools layer (if you are not using ITCSS, @import it somewhere toward the beginning of your project).
  • @import _trumps.nudge.scss into your Trumps layer (if you are not using ITCSS, @import it somewhere toward the end of your project).

Configuring

You can disable Nudge features by setting $nudge-[feature] to false just before you @import _tools.nudge.scss, e.g.:

$nudge-single-spaces:         false;
$nudge-underscores:           false;
$nudge-camel-case:            false;
@import "tools.nudge";

This will stop Nudge from reporting on the use of single spaces in class attributes, the use of underscores in class names, and the use of camel case in class names.

Incorrect Nesting

To check for incorrect nesting of a class, call the nudge-nest() mixin within it, passing in the expected ancestor. For example, in our HTML, .widget__title must always live inside of .widget, so in our Sass we would write:

.widget {
  [styles]
}

  .widget__title {
    @include nudge-nest('.widget');
    [styles]
  }

Now we will see an error in our UI if .widget__title is used outside of the context of .widget.

Deprecated Selectors

To configure our deprecated selectors, simply copy/paste the $nudge-deprecated-selectors-list map out of _trumps.nudge.scss and into your manifest file (e.g. main.scss). Place it just before your @import for the _trumps.nudge.scss file, then delete the !default flag and replace the example selectors with your own, e.g.:

$nudge-deprecated-selectors-list: (
  '.btn': '.c-btn',
);
@import "trumps.nudge";

The Rules

  • Incorrect Nesting: Check that a selector hasn’t been used outside of its required context. Display an error if it has.
  • No IDs We shouldn’t use IDs in CSS, so display a warning any time we find one.
  • Single-Space Delimited class Attributes: Prefer two spaces separating individual strings in the class attribute. Display a warning if we find single spaces.
  • Improper Use of BEM Modifiers: Display an error if someone tries to use a Modifier without also having defined a Block.
  • Underscores as Delimiters: We use hyphens to delimit strings, so display a warning if we find any classes with single hyphens.
  • Use of Camel Case: We do not use camel case, so display a warning if we find any capital letters in a class.
  • Deprecated Selectors: Display a warning if we find any classes that we have deemed deprecated.

More Repositories

1

inuit.css

Powerful, scalable, Sass-based, BEM, OOCSS framework.
CSS
3,838
star
2

CSS-Guidelines

High-level guidelines for writing manageable, maintainable CSS
3,653
star
3

ct

Let’s take a look inside your <head>…
CSS
1,848
star
4

csswizardry-grids

Simple, fluid, nestable, flexible, Sass-based, responsive grid system.
CSS
1,491
star
5

typecsset

A small Sass library for setting type on the web.
CSS
713
star
6

csswizardry.github.com

My site.
HTML
463
star
7

beautons

A beautifully simple button toolkit
CSS
211
star
8

csscv

A simple, opinionated stylesheet for formatting semantic HTML to look like a CSS file.
CSS
205
star
9

vanilla

My personal starting point for new builds.
HTML
184
star
10

discovr

CSS Architecture workshop files
CSS
172
star
11

frcss

CSS
107
star
12

dotfiles

Starting small… my dotfiles for a few things.
Vim Script
102
star
13

inuit.css-web-template

Web template for housing the inuit.css framework as submodule
CSS
88
star
14

ama

Ask me anything!
58
star
15

recipes

Collection of things I like cooking
42
star
16

pr.ofile.me

Digital, mobile business cards
40
star
17

hry.rbrts.me

Personal hub site.
Racket
20
star
18

build-along-1

The first CSS Wizardry build-along
17
star
19

css-architecture

Workshop materials
CSS
16
star
20

fluid-grids

PHP
15
star
21

extend-vs-mixin

CSS
13
star
22

work

Dedicated ‘work’ page for CSS Wizardry
HTML
12
star
23

fep

9
star
24

sampenrose.co.uk

Portfolio
6
star
25

demo-component

CSS
5
star
26

harry.is

HTML
3
star
27

gilliansibthorpe.com

HTML
2
star
28

questions-for-consultants-issues

Public issue tracker for my eBook, Questions for Consultants
2
star
29

test

1
star
30

wishlist

Because I’m greedy like that…
1
star
31

press

Bios and stuff…
1
star
32

toolkit-core

CSS
1
star
33

piccalilli-burger-menu-demo

HTML
1
star
34

markrabey.github.io

CSS
1
star
35

nightingale-demo

HTML
1
star
36

bower-demo

CSS
1
star