Repository: styled-components/stylelint-processor-styled-components
Pull request #25 (2017-04-24 17:59:05)

Add newline between components' styles
Continues #11.

I just added the tests asked in the previous PR.

First commit (tests only) should break the CI.


Patch:
diff --git a/src/index.js b/src/index.js
index 4ea4cc0..4602d44 100644
--- a/src/index.js
+++ b/src/index.js
@@ -48,7 +48,7 @@ module.exports = (/* options */) => ({
       ],
     })
 
-    let extractedCSS = ''
+    const extractedCSS = []
     let importedNames = {
       default: 'styled',
       css: 'css',
@@ -70,16 +70,16 @@ module.exports = (/* options */) => ({
         const fixedContent = fixIndentation(content).text
         const wrapperFn = helper === 'keyframes' ? wrapKeyframes : wrapSelector
         const wrappedContent = wrapperFn(fixedContent)
-        extractedCSS += wrappedContent
+        extractedCSS.push(wrappedContent)
         // Save source location, merging existing corrections with current corrections
         sourceMapsCorrections[absolutePath] = Object.assign(
           sourceMapsCorrections[absolutePath],
-          getSourceMap(extractedCSS, wrappedContent, node.loc.start.line)
+          getSourceMap(extractedCSS.join('\n'), wrappedContent, node.loc.start.line)
         )
       },
     })
 
-    return extractedCSS
+    return extractedCSS.join('\n')
   },
   // Fix sourcemaps
   result(stylelintResult, filepath) {


Test patch:
diff --git a/test/fixtures/simple/imports.js b/test/fixtures/simple/imports.js
index c4e560e..437613e 100644
--- a/test/fixtures/simple/imports.js
+++ b/test/fixtures/simple/imports.js
@@ -13,6 +13,7 @@ const animation = notKeyframes`
 0% {
 	opacity: 0;
 }
+
 100% {
 	opacity: 1;
 }
diff --git a/test/fixtures/simple/nesting.js b/test/fixtures/simple/nesting.js
index fe9b48d..7398381 100644
--- a/test/fixtures/simple/nesting.js
+++ b/test/fixtures/simple/nesting.js
@@ -10,6 +10,7 @@ const Button = styled.button`
 // Selectors
 const Button2 = styled.button`
   color: red;
+
   &:hover {
     color: blue;
   }
@@ -18,6 +19,7 @@ const Button2 = styled.button`
 // Complex selectors
 const Button3 = styled.button`
   color: red;
+
   &:placeholder {
     color: blue;
   }
diff --git a/test/simple.test.js b/test/simple.test.js
index 4469a29..3157793 100644
--- a/test/simple.test.js
+++ b/test/simple.test.js
@@ -5,6 +5,10 @@ const processor = path.join(__dirname, '../src/index.js')
 const rules = {
   'block-no-empty': true,
   indentation: 2,
+  'rule-empty-line-before': ['always-multi-line', {
+    except: ['first-nested'],
+    ignore: ['after-comment'],
+  }],
 }
 
 describe('simple', () => {
@@ -101,13 +105,14 @@ describe('simple', () => {
     })
 
     it('should have 11 warnings (i.e. wrong lines of code)', () => {
-      expect(data.results[0].warnings.length).toEqual(11)
+      expect(data.results[0].warnings.length).toEqual(13)
     })
 
-    it('should all be indentation warnings', () => {
-      data.results[0].warnings.forEach((warning) => {
-        expect(warning.rule).toEqual('indentation')
-      })
+    it('should be indentation and "empty line before" warnings', () => {
+      const warnings = data.results[0].warnings
+        .reduce((all, { rule }) => all.includes(rule) ? all : all.concat(rule), [])
+
+      expect(warnings).toEqual(['indentation', 'rule-empty-line-before'])
     })
   })