Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Sep 17, 2016
0 parents commit 3b1c0c6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/node_modules
6 changes: 6 additions & 0 deletions example.css
@@ -0,0 +1,6 @@
@charset 'utf-8';
.foo-bar {
}
.foo-bar > .el {
color: blue;
}
26 changes: 26 additions & 0 deletions index.js
@@ -0,0 +1,26 @@
var postcss = require('postcss')

module.exports = postcss.plugin('postcss-rscss-linter', function (options, secOptions) {
return function (root, result) {
return walk(root, result)
}
})

function walk (node, state) {
if (node.type === 'rule') {
state = walkRule(node, state)
}

if (node.nodes) {
state = node.nodes.reduce(function (state, subnode) {
return walk(subnode, state)
}, state)
}

return state
}

function walkRule (node, state) {
state.messages.push({ 'rule': node.selector })
return state
}
18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{
"name": "rscss-lint",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Rico Sta. Cruz <rico@ricostacruz.com> (http://ricostacruz.com)",
"license": "MIT",
"dependencies": {
"postcss": "5.1.2"
},
"devDependencies": {
"tape": "4.6.0"
}
}
8 changes: 8 additions & 0 deletions test.js
@@ -0,0 +1,8 @@
const postcss = require('postcss')
const linter = require('./index')

const css = require('fs').readFileSync(__dirname + '/example.css', 'utf-8')

postcss([linter]).process(css).then(result => {
console.log(result)
})

0 comments on commit 3b1c0c6

Please sign in to comment.