Merge pull request #623 from danielbayley/master
Improve CSScomb support
This commit is contained in:
commit
266ad49ab4
107
docs/options.md
107
docs/options.md
|
@ -495,6 +495,58 @@ If in CSS values leading 0s immediately preceeding a decimal should be removed o
|
|||
}
|
||||
```
|
||||
|
||||
#### [CSS - comb custom config file](#css---comb-custom-config-file)
|
||||
|
||||
**Namespace**: `css`
|
||||
|
||||
**Key**: `configPath`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Supported Beautifiers**: [`CSScomb`](#csscomb)
|
||||
|
||||
**Description**:
|
||||
|
||||
Path to custom CSScomb config file, used in absense of a `.csscomb.json` or `.csscomb.cson` at the root of your project. (Supported by CSScomb)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"css": {
|
||||
"configPath": ""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [CSS - comb predefined config](#css---comb-predefined-config)
|
||||
|
||||
**Namespace**: `css`
|
||||
|
||||
**Key**: `predefinedConfig`
|
||||
|
||||
**Default**: `csscomb`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `csscomb` `yandex` `zen`
|
||||
|
||||
**Supported Beautifiers**: [`CSScomb`](#csscomb)
|
||||
|
||||
**Description**:
|
||||
|
||||
Used if neither a project or custom config file exists. (Supported by CSScomb)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"css": {
|
||||
"predefinedConfig": "csscomb"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [D - Config Path](#d---config-path)
|
||||
|
||||
**Namespace**: `d`
|
||||
|
@ -5997,6 +6049,61 @@ If a terminating comma should be inserted into arrays, object literals, and dest
|
|||
```
|
||||
|
||||
|
||||
### CSScomb
|
||||
|
||||
#### [CSS - comb custom config file](#css---comb-custom-config-file)
|
||||
|
||||
**Namespace**: `css`
|
||||
|
||||
**Key**: `configPath`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Supported Beautifiers**: [`CSScomb`](#csscomb)
|
||||
|
||||
**Description**:
|
||||
|
||||
Path to custom CSScomb config file, used in absense of a `.csscomb.json` or `.csscomb.cson` at the root of your project. (Supported by CSScomb)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"css": {
|
||||
"configPath": ""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [CSS - comb predefined config](#css---comb-predefined-config)
|
||||
|
||||
**Namespace**: `css`
|
||||
|
||||
**Key**: `predefinedConfig`
|
||||
|
||||
**Default**: `csscomb`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `csscomb` `yandex` `zen`
|
||||
|
||||
**Supported Beautifiers**: [`CSScomb`](#csscomb)
|
||||
|
||||
**Description**:
|
||||
|
||||
Used if neither a project or custom config file exists. (Supported by CSScomb)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"css": {
|
||||
"predefinedConfig": "csscomb"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Gherkin formatter
|
||||
|
||||
#### [gherkin - Indent size](#gherkin---indent-size)
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
{
|
||||
"name": "Zhang YANG",
|
||||
"url": "https://github.com/ProgramFan"
|
||||
},
|
||||
{
|
||||
"name": "Daniel Bayley",
|
||||
"url": "https://github.com/danielbayley"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
|
@ -83,6 +87,7 @@
|
|||
"node-dir": "^0.1.8",
|
||||
"node-uuid": "^1.4.3",
|
||||
"prettydiff": "^1.12.19",
|
||||
"season": "^5.3.0",
|
||||
"space-pen": "^5.1.1",
|
||||
"strip-json-comments": "^1.0.2",
|
||||
"temp": "^0.8.3",
|
||||
|
|
|
@ -6,10 +6,13 @@ module.exports = class JSBeautify extends Beautifier
|
|||
|
||||
options: {
|
||||
# TODO: Add support for options
|
||||
CSS: false
|
||||
LESS: false
|
||||
Sass: false
|
||||
SCSS: false
|
||||
_:
|
||||
configPath: true
|
||||
predefinedConfig: true
|
||||
CSS: true
|
||||
LESS: true
|
||||
Sass: true
|
||||
SCSS: true
|
||||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
|
@ -18,16 +21,22 @@ module.exports = class JSBeautify extends Beautifier
|
|||
|
||||
# Require
|
||||
Comb = require('csscomb')
|
||||
expandHomeDir = require('expand-home-dir')
|
||||
CSON = require('season')
|
||||
|
||||
config = null
|
||||
try
|
||||
# Load from Project's .csscomb.json
|
||||
projectConfigPath = atom.project.getDirectories()?[0]?.resolve('.csscomb.json')
|
||||
config = require(projectConfigPath) # Will throw error if does not exist
|
||||
catch e
|
||||
# Fallback to csscomb
|
||||
config = Comb.getConfig('csscomb')
|
||||
# TODO: Add support to select CSSComb predefined config's name
|
||||
try # Load from project config file, throwing error if neither exist
|
||||
project = atom.project.getDirectories()?[0]
|
||||
try
|
||||
config = CSON.readFileSync(project?.resolve '.csscomb.cson')
|
||||
catch
|
||||
config = require(project?.resolve '.csscomb.json')
|
||||
catch
|
||||
try # Load from custom config
|
||||
config = CSON.readFileSync(expandHomeDir options.configPath)
|
||||
catch
|
||||
# Fallback to [selected] CSScomb predifined config
|
||||
config = Comb.getConfig(options.predefinedConfig)
|
||||
# console.log('config', config, options)
|
||||
# Configure
|
||||
comb = new Comb(config)
|
||||
|
|
|
@ -83,4 +83,16 @@ module.exports = {
|
|||
default: false
|
||||
description: "If in CSS values leading 0s immediately preceeding \
|
||||
a decimal should be removed or prevented."
|
||||
configPath:
|
||||
title: "comb custom config file"
|
||||
type: 'string'
|
||||
default: ""
|
||||
description: "Path to custom CSScomb config file, used in absense of a \
|
||||
`.csscomb.json` or `.csscomb.cson` at the root of your project."
|
||||
predefinedConfig:
|
||||
title: "comb predefined config"
|
||||
type: 'string'
|
||||
default: "csscomb"
|
||||
description: "Used if neither a project or custom config file exists."
|
||||
enum: ["csscomb", "yandex", "zen"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue