Skip to content

Commit

Permalink
Added "insertNewLineAroundImports" formatting option
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsManta committed Apr 27, 2017
1 parent 7937cb2 commit dc9898e
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 35 deletions.
50 changes: 27 additions & 23 deletions docs/format.js

Large diffs are not rendered by default.

42 changes: 35 additions & 7 deletions docs/index.html

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions edge/createFormattingOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const schema = {
`
}
},
insertNewLineAroundImports: {
description: 'Insert a new-line around a group of <code>@import</code>/<code>@require</code>(s).\nOnly apply to imports outside a block when set to <code>"root"</code>, or only apply to imports inside a block when set to <code>"nested"</code>.\n<span class="no-vsce">Check the detailed examples <a href="#option-insert-newline-around-any">below</a>.</span>',
oneOf: [true, false, 'root', 'nested'],
default: true,
},
insertNewLineAroundBlocks: {
description: 'Insert a new-line around blocks.\nOnly apply to top-level blocks when set to <code>"root"</code>, or only apply to nested blocks when set to <code>"nested"</code>.\n<span class="no-vsce">Check the detailed examples <a href="#option-insert-newline-around-any">below</a>.</span>',
oneOf: [true, false, 'root', 'nested'],
Expand All @@ -48,9 +53,9 @@ const schema = {
default: true,
},
insertNewLineAroundOthers: {
description: 'Insert a new-line around a group of non-properties and non-blocks.\nOnly apply to others outside a block when set to <code>"root"</code>, or only apply to others inside a block when set to <code>"nested"</code>.\n<span class="no-vsce">Check the detailed examples <a href="#option-insert-newline-around-any">below</a>.</span>',
description: 'Insert a new-line around a group of non-properties, non-imports and non-blocks.\nOnly apply to others outside a block when set to <code>"root"</code>, or only apply to others inside a block when set to <code>"nested"</code>.\n<span class="no-vsce">Check the detailed examples <a href="#option-insert-newline-around-any">below</a>.</span>',
oneOf: [true, false, 'root', 'nested'],
default: true,
default: false,
},
insertNewLineBetweenSelectors: {
description: 'Insert or remove a new-line between selectors.',
Expand Down
6 changes: 5 additions & 1 deletion edge/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function format(content, options = {}) {
return false
}

// Insert CSS body
// Insert CSS body and new-lines between them
outputBuffer.append(_.chain(groups)
.map(group => {
const nodeType = getType(group[0])
Expand All @@ -254,6 +254,7 @@ function format(content, options = {}) {
if (
nodeType === 'Block' && checkIf(options.insertNewLineAroundBlocks) ||
nodeType === 'Property' && checkIf(options.insertNewLineAroundProperties) ||
nodeType === 'Import' && checkIf(options.insertNewLineAroundImports) ||
nodeType === 'Other' && checkIf(options.insertNewLineAroundOthers)
) {
newLineAround = options.newLineChar
Expand Down Expand Up @@ -1055,6 +1056,9 @@ function format(content, options = {}) {
if (inputNode instanceof Stylus.nodes.Property) {
return 'Property'

} else if (inputNode instanceof Stylus.nodes.Import) {
return 'Import'

} else if (inputNode.block !== undefined || (inputNode instanceof Stylus.nodes.Ident && inputNode.val.block !== undefined)) {
return 'Block'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"insertNewLineAroundBlocks": true,
"insertNewLineAroundProperties": true,
"insertNewLineAroundImports": true,
"insertNewLineAroundOthers": true,
"newLineChar": "\r\n"
}
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-1/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a'
@require 'b'
.class1
@import 'c'
mixin()
display func()
func()
Expand Down
5 changes: 5 additions & 0 deletions spec/option-insert-new-line-around-any-1/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@import 'a';
@require 'b';

.class1 {
@import 'c';

mixin() {
display: func();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"insertNewLineAroundBlocks": true,
"insertNewLineAroundProperties": false,
"insertNewLineAroundImports": false,
"insertNewLineAroundOthers": false,
"newLineChar": "\r\n"
}
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-2/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a'
@require 'b'
.class1
@import 'c'
mixin()
display func()
func()
Expand Down
5 changes: 5 additions & 0 deletions spec/option-insert-new-line-around-any-2/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@import 'a';
@require 'b';

.class1 {
@import 'c';

mixin() {
display: func();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"insertNewLineAroundBlocks": false,
"insertNewLineAroundProperties": false,
"insertNewLineAroundImports": false,
"insertNewLineAroundOthers": false,
"newLineChar": "\r\n"
}
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-3/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a'
@require 'b'
.class1
@import 'c'
mixin()
display func()
func()
Expand Down
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-3/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a';
@require 'b';
.class1 {
@import 'c';
mixin() {
display: func();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"insertNewLineAroundBlocks": "root",
"insertNewLineAroundProperties": false,
"insertNewLineAroundImports": "root",
"insertNewLineAroundOthers": "root",
"newLineChar": "\r\n"
}
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-4/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a'
@require 'b'
.class1
@import 'c'
mixin()
display func()
func()
Expand Down
4 changes: 4 additions & 0 deletions spec/option-insert-new-line-around-any-4/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@import 'a';
@require 'b';

.class1 {
@import 'c';
mixin() {
display: func();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"insertNewLineAroundBlocks": "nested",
"insertNewLineAroundProperties": false,
"insertNewLineAroundImports": "nested",
"insertNewLineAroundOthers": "nested",
"newLineChar": "\r\n"
}
3 changes: 3 additions & 0 deletions spec/option-insert-new-line-around-any-5/input.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@import 'a'
@require 'b'
.class1
@import 'c'
mixin()
display func()
func()
Expand Down
4 changes: 4 additions & 0 deletions spec/option-insert-new-line-around-any-5/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
@import 'a';
@require 'b';
.class1 {
@import 'c';

mixin() {
display: func();
}
Expand Down
3 changes: 2 additions & 1 deletion spec/option-insert-semicolon-false/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ body
return 2
}
foo = 1 + 2
bar = 1 ? 2 : 3
bar = 1 ? 2 : 3
@extend .class1
2 changes: 2 additions & 0 deletions spec/option-insert-semicolon-false/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@namespace 'http://www.w3.org/1999/xhtml'

@import 'path1'

body {
Expand All @@ -12,4 +13,5 @@ body {

foo = 1 + 2
bar = 1 ? 2 : 3
@extend .class1
}
3 changes: 2 additions & 1 deletion spec/option-insert-semicolon-true/input.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ body
return 2
}
foo = 1 + 2
bar = 1 ? 2 : 3
bar = 1 ? 2 : 3
@extend .class1
2 changes: 2 additions & 0 deletions spec/option-insert-semicolon-true/output.styl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@namespace 'http://www.w3.org/1999/xhtml';

@import 'path1';

body {
Expand All @@ -12,4 +13,5 @@ body {

foo = 1 + 2;
bar = 1 ? 2 : 3;
@extend .class1;
}

0 comments on commit dc9898e

Please sign in to comment.