Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with shorthand percentage values #441

Merged
merged 3 commits into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/rules/shorthand-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Rule `shorthand-values` will enforce that values in their shorthand form are as

When `allowed-shorthands` is left at default, the following is enforced:

```yml
# .sass-lint.yml
shorthand-values: 1
```

```scss
margin: 1px 1px 1px 1px;

Expand All @@ -31,6 +36,15 @@ margin: 1px 2px 3px;

When `allowed-shorthands` is `[1]`, the following is enforced:

```yml
# .sass-lint.yml
shorthand-values:
- 1
-
allowed-shorthands:
- 1
```

```scss
margin: 1px 1px 1px 1px;

Expand All @@ -46,6 +60,16 @@ margin: 1px 2px 1px 2px;

When `allowed-shorthands` is `[1, 2]`, the following is enforced:

```yml
# .sass-lint.yml
shorthand-values:
- 1
-
allowed-shorthands:
- 1
- 2
```

```scss
margin: 1px 1px 1px 1px;

Expand Down
6 changes: 6 additions & 0 deletions lib/rules/shorthand-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ module.exports = {
});
}

else if (val.is('percentage')) {
val.forEach(function (el) {
fullVal += el.content + '%';
});
}

else if (val.is('operator') || val.is('ident') || val.is('number') || val.is('unaryOperator')) {
fullVal += val.content;
}
Expand Down
32 changes: 16 additions & 16 deletions tests/rules/shorthand-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('shorthand values - scss', function () {
lint.test(file, {
'shorthand-values': 1
}, function (data) {
lint.assert.equal(49, data.warningCount);
lint.assert.equal(54, data.warningCount);
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(21, data.warningCount);
lint.assert.equal(23, data.warningCount);
done();
});
});
Expand All @@ -44,7 +44,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(23, data.warningCount);
lint.assert.equal(26, data.warningCount);
done();
});
});
Expand All @@ -60,7 +60,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(29, data.warningCount);
lint.assert.equal(32, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -109,7 +109,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(42, data.warningCount);
lint.assert.equal(46, data.warningCount);
done();
});
});
Expand All @@ -126,7 +126,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -144,7 +144,7 @@ describe('shorthand values - scss', function () {
}
]
}, function (data) {
lint.assert.equal(49, data.warningCount);
lint.assert.equal(54, data.warningCount);
done();
});
});
Expand All @@ -161,7 +161,7 @@ describe('shorthand values - sass', function () {
lint.test(file, {
'shorthand-values': 1
}, function (data) {
lint.assert.equal(49, data.warningCount);
lint.assert.equal(54, data.warningCount);
done();
});
});
Expand All @@ -177,7 +177,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(21, data.warningCount);
lint.assert.equal(23, data.warningCount);
done();
});
});
Expand All @@ -193,7 +193,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(23, data.warningCount);
lint.assert.equal(26, data.warningCount);
done();
});
});
Expand All @@ -209,7 +209,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(29, data.warningCount);
lint.assert.equal(32, data.warningCount);
done();
});
});
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -258,7 +258,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(42, data.warningCount);
lint.assert.equal(46, data.warningCount);
done();
});
});
Expand All @@ -275,7 +275,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(36, data.warningCount);
lint.assert.equal(40, data.warningCount);
done();
});
});
Expand All @@ -293,7 +293,7 @@ describe('shorthand values - sass', function () {
}
]
}, function (data) {
lint.assert.equal(49, data.warningCount);
lint.assert.equal(54, data.warningCount);
done();
});
});
Expand Down
33 changes: 33 additions & 0 deletions tests/sass/shorthand-values.sass
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,36 @@

.value-four-diff-four-negative-mixed
margin: -1px 1px -1rem -1rem

.value-percentage
margin: 1%

.value-two-percentage
margin: 1% 1%

.value-two-diff-percentage
margin: 1% -1%

.value-three-diff-one-percentage
margin: 1% 2% 1%

.value-three-diff-two-percentage
margin: 1% 2% -1%

.value-four-percentage
margin: 1% 1% 1% 1%

.value-four-diff-one-percentage
margin: 1% 1% 1% -1%

.value-four-diff-two-percentage
margin: 1% -1% 1% -1%

.value-four-diff-three-percentage
margin: 1% -1% -1% -1%

.value-four-diff-four-percentage
margin: 1% -2% -3% 4%

.value-four-diff-four-percentage-mixed
margin: -1% -1% -1rem -1rem
44 changes: 44 additions & 0 deletions tests/sass/shorthand-values.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,47 @@
.value-four-diff-four-negative-mixed {
margin: -1px 1px -1rem -1rem;
}

.value-percentage {
margin: 1%;
}

.value-two-percentage {
margin: 1% 1%;
}

.value-two-diff-percentage {
margin: 1% -1%;
}

.value-three-diff-one-percentage {
margin: 1% 2% 1%;
}

.value-three-diff-two-percentage {
margin: 1% 2% -1%;
}

.value-four-percentage {
margin: 1% 1% 1% 1%;
}

.value-four-diff-one-percentage {
margin: 1% 1% 1% -1%;
}

.value-four-diff-two-percentage {
margin: 1% -1% 1% -1%;
}

.value-four-diff-three-percentage {
margin: 1% -1% -1% -1%;
}

.value-four-diff-four-percentage {
margin: 1% -2% -3% 4%;
}

.value-four-diff-four-percentage-mixed {
margin: -1% -1% -1rem -1rem;
}