Skip to content

Commit

Permalink
Update development practices
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jun 13, 2021
1 parent d7b9045 commit 8373d32
Show file tree
Hide file tree
Showing 21 changed files with 1,799 additions and 3,526 deletions.
2 changes: 1 addition & 1 deletion liner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function liner (tokens) {
module.exports = function liner(tokens) {
let line = []
let result = [line]
let brackets = 0
Expand Down
64 changes: 37 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
"license": "MIT",
"repository": "postcss/sugarss",
"scripts": {
"test": "jest && eslint-ci ."
"test": "jest && eslint ."
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/postcss/"
},
"dependencies": {
"postcss": "^8.1.6"
},
"engines": {
"node": ">=12.0"
},
Expand All @@ -31,36 +28,49 @@
"require": "./index.js",
"import": "./index.mjs"
},
"./": "./"
"./parse": "./parse.js",
"./stringify": "./stringify.js",
"./tokenize": "./tokenize.js"
},
"peerDependencies": {
"postcss": "^8.2.14"
},
"devDependencies": {
"@logux/eslint-config": "^42.2.0",
"clean-publish": "^1.1.8",
"eslint": "^7.12.1",
"eslint-ci": "^1.0.0",
"eslint-config-standard": "^16.0.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.0",
"@logux/eslint-config": "^45.4.4",
"clean-publish": "^2.2.0",
"eslint": "^7.28.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-let": "^1.1.0",
"eslint-plugin-prettierx": "^0.14.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^4.0.2",
"eslint-plugin-unicorn": "^23.0.0",
"husky": "^4.3.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.1",
"postcss-parser-tests": "^8.3.3",
"postcss-sharec-config": "^0.1.9"
"eslint-plugin-unicorn": "^33.0.1",
"jest": "^27.0.4",
"lint-staged": "^11.0.0",
"postcss": "^8.2.14",
"postcss-parser-tests": "^8.3.5",
"postcss-sharec-config": "^0.4.1",
"prettier": "^2.2.1",
"simple-git-hooks": "^2.4.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"prettier": {
"arrowParens": "avoid",
"jsxSingleQuote": false,
"quoteProps": "consistent",
"semi": false,
"singleQuote": true,
"trailingComma": "none"
},
"lint-staged": {
"*.js": "eslint --fix"
"*.js": [
"prettier --write",
"eslint --fix"
]
},
"eslintConfig": {
"extends": "@logux/eslint-config"
Expand All @@ -75,6 +85,6 @@
},
"sharec": {
"config": "postcss-sharec-config",
"version": "0.1.9"
"version": "0.4.1"
}
}
2 changes: 1 addition & 1 deletion parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let tokenizer = require('./tokenize')
let Parser = require('./parser')
let liner = require('./liner')

module.exports = function parse (source, opts) {
module.exports = function parse(source, opts) {
let input = new Input(source, opts)

let parser = new Parser(input)
Expand Down
42 changes: 21 additions & 21 deletions parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let { Declaration, Comment, AtRule, Rule, Root } = require('postcss')

module.exports = class Parser {
constructor (input) {
constructor(input) {
this.input = input

this.pos = 0
Expand All @@ -16,7 +16,7 @@ module.exports = class Parser {
this.root.source = { input, start: { line: 1, column: 1 } }
}

loop () {
loop() {
let part
while (this.pos < this.parts.length) {
part = this.parts[this.pos]
Expand Down Expand Up @@ -61,15 +61,15 @@ module.exports = class Parser {
}
}

comment (part) {
comment(part) {
let token = part.tokens[0]
let node = new Comment()
this.init(node, part)
node.source.end = { line: token[4], column: token[5] }
this.commentText(node, token)
}

atrule (part) {
atrule(part) {
let atword = part.tokens[0]
let params = part.tokens.slice(1)

Expand All @@ -93,7 +93,7 @@ module.exports = class Parser {
this.raw(node, 'params', params, atword)
}

decl (part) {
decl(part) {
let node = new Declaration()
this.init(node, part)

Expand Down Expand Up @@ -174,7 +174,7 @@ module.exports = class Parser {
this.raw(node, 'value', value, colon)
}

rule (part) {
rule(part) {
let node = new Rule()
this.init(node, part)

Expand All @@ -195,7 +195,7 @@ module.exports = class Parser {

/* Helpers */

indent (part) {
indent(part) {
let indent = part.indent.length
let isPrev = typeof this.prevIndent !== 'undefined'

Expand Down Expand Up @@ -232,7 +232,7 @@ module.exports = class Parser {
this.prevIndent = indent
}

init (node, part) {
init(node, part) {
this.indent(part)

if (!this.current.nodes) this.current.nodes = []
Expand All @@ -249,31 +249,31 @@ module.exports = class Parser {
}
}

checkCurly (tokens) {
checkCurly(tokens) {
for (let token of tokens) {
if (token[0] === '{') {
this.error('Unnecessary curly bracket', token[2], token[3])
}
}
}

checkSemicolon (tokens) {
checkSemicolon(tokens) {
for (let token of tokens) {
if (token[0] === ';') {
this.error('Unnecessary semicolon', token[2], token[3])
}
}
}

keepTrailingSpace (node, tokens) {
keepTrailingSpace(node, tokens) {
let lastSpace = tokens[tokens.length - 1]
if (lastSpace && lastSpace[0] === 'space') {
tokens.pop()
node.raws.sssBetween = lastSpace[1]
}
}

firstSpaces (tokens) {
firstSpaces(tokens) {
let result = ''
for (let i = 0; i < tokens.length; i++) {
if (tokens[i][0] === 'space' || tokens[i][0] === 'newline') {
Expand All @@ -286,7 +286,7 @@ module.exports = class Parser {
return result
}

raw (node, prop, tokens, altLast) {
raw(node, prop, tokens, altLast) {
let token, type
let length = tokens.length
let value = ''
Expand Down Expand Up @@ -329,7 +329,7 @@ module.exports = class Parser {
}
}

nextNonComment (pos) {
nextNonComment(pos) {
let next = pos
let part
while (next < this.parts.length) {
Expand All @@ -340,7 +340,7 @@ module.exports = class Parser {
return part
}

commentText (node, token) {
commentText(node, token) {
let text = token[1]
if (token[6] === 'inline') {
node.raws.inline = true
Expand All @@ -363,28 +363,28 @@ module.exports = class Parser {

// Errors

error (msg, line, column) {
error(msg, line, column) {
throw this.input.error(msg, line, column)
}

unnamedAtrule (token) {
unnamedAtrule(token) {
this.error('At-rule without name', token[2], token[3])
}

unnamedDecl (token) {
unnamedDecl(token) {
this.error('Declaration without name', token[2], token[3])
}

indentedFirstLine (part) {
indentedFirstLine(part) {
this.error('First line should not have indent', part.number, 1)
}

wrongIndent (expected, real, part) {
wrongIndent(expected, real, part) {
let msg = `Expected ${expected} indent, but get ${real}`
this.error(msg, part.number, 1)
}

badProp (token) {
badProp(token) {
this.error('Unexpected separator in property', token[2], token[3])
}
}
4 changes: 2 additions & 2 deletions preprocess.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function indentError (input, l, p) {
function indentError(input, l, p) {
throw input.error('Mixed tabs and spaces are not allowed', l, p + 1)
}

module.exports = function preprocess (input, lines) {
module.exports = function preprocess(input, lines) {
let indentType
let prevNumber = 0
let parts = lines.map(line => {
Expand Down
24 changes: 12 additions & 12 deletions stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const DEFAULT_RAWS = {
}

module.exports = class Stringifier {
constructor (builder) {
constructor(builder) {
this.builder = builder
}

stringify (node, semicolon) {
stringify(node, semicolon) {
this[node.type](node, semicolon)
}

root (node) {
root(node) {
this.body(node)
if (node.raws.after) this.builder(node.raws.after)
}

comment (node) {
comment(node) {
let left = DEFAULT_RAWS.commentLeft
let right = DEFAULT_RAWS.commentRight
if (this.has(node.raws.left)) left = node.raws.left
Expand All @@ -40,7 +40,7 @@ module.exports = class Stringifier {
}
}

decl (node) {
decl(node) {
let between = node.raws.between || DEFAULT_RAWS.colon
let string = node.prop + between + this.rawValue(node, 'value')

Expand All @@ -51,11 +51,11 @@ module.exports = class Stringifier {
this.builder(string, node)
}

rule (node) {
rule(node) {
this.block(node, this.rawValue(node, 'selector'))
}

atrule (node) {
atrule(node) {
let name = '@' + node.name
let params = node.params ? this.rawValue(node, 'params') : ''

Expand All @@ -68,7 +68,7 @@ module.exports = class Stringifier {
this.block(node, name + params)
}

body (node) {
body(node) {
let indent = node.root().raws.indent || DEFAULT_RAWS.indent

for (let i = 0; i < node.nodes.length; i++) {
Expand All @@ -83,13 +83,13 @@ module.exports = class Stringifier {
}
}

block (node, start) {
block(node, start) {
let between = node.raws.sssBetween || ''
this.builder(start + between, node, 'start')
if (this.has(node.nodes)) this.body(node)
}

indent (node, step) {
indent(node, step) {
let result = ''
while (node.parent) {
result += step
Expand All @@ -98,11 +98,11 @@ module.exports = class Stringifier {
return result
}

has (value) {
has(value) {
return typeof value !== 'undefined'
}

rawValue (node, prop) {
rawValue(node, prop) {
let value = node[prop]
let raw = node.raws[prop]
if (raw && raw.value === value) {
Expand Down
2 changes: 1 addition & 1 deletion stringify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let Stringifier = require('./stringifier')

module.exports = function stringify (node, builder) {
module.exports = function stringify(node, builder) {
let str = new Stringifier(builder)
str.stringify(node)
}
Loading

0 comments on commit 8373d32

Please # to comment.