This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

selector-nest-combinators

1.0.4 • Public • Published

tc/selector-nest-combinators

Require or disallow nesting of combinators in selectors

/* Examples of selectors without nesting of combinators */
.foo .bar {}

.foo.bar {}

.foo > .bar {}

.foo:hover {}

/* Corresponding selectors with combinators nested */
.foo {
  .bar {}
}

.foo {
  &.bar {}
}

.foo {
  & > .bar {}
}

.foo {
  &:hover {}
}

Options

string: "always"|"never"

"always"

Every combinator in a selector must be nested where possible without altering the existing resolved selector.

Sections of selectors preceding a parent selector are ignored with always. e.g.

.foo {
  .bar.baz & {}
}

Sections of selectors within pseudo selectors are also ignored with always. e.g.

.foo {
  &:not(.bar .baz) {}
}

while this could be refactored to:

.bar {
  .baz {
    .foo:not(&) {}
  }
}

There are variances in the way this is compiled between compilers, therefore for the purposes of this rule the selector sections within pseudo selectors are being ignored.

The following patterns are considered warnings:

.foo .bar {}
.foo.bar {}
.foo > .bar {}
.foo:hover {}
a[href] {}
* + li {}
:nth-child(2n - 1):last-child {}

The following patterns are not considered warnings:

.foo {
  .bar {}
}
.foo {
  &.bar {}
}
.foo {
  & > .bar {}
}
.foo {
  &:hover {}
}
a {
  &[href] {}
}
* {
  & + li {}
}
:nth-child(2n - 1) {
  &:last-child {}
}

"never"

Nested of selectors are not allowed.

The following patterns are considered warnings:

.foo {
  .bar {}
}
.foo {
  &.bar {}
}
.foo {
  & > .bar {}
}
.foo {
  &:hover {}
}
a {
  &[href] {}
}
* {
  & + li {}
}
:nth-child(2n - 1) {
  &:last-child {}
}

The following patterns are not considered warnings:

.foo .bar {}
.foo.bar {}
.foo > .bar {}
.foo:hover {}
a[href] {}
* + li {}
:nth-child(2n - 1):last-child {}

Package Sidebar

Install

npm i selector-nest-combinators

Weekly Downloads

171

Version

1.0.4

License

MIT

Unpacked Size

378 kB

Total Files

249

Last publish

Collaborators

  • kiforks