Improve CSScomb support
Add setting for custom config file path and support for CSON in addition to the standard JSON config. Signed-off-by: Daniel Bayley <daniel.bayley@me.com>
This commit is contained in:
parent
ff7a0a4efb
commit
4a06a683c6
115
docs/options.md
115
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)
|
#### [D - Config Path](#d---config-path)
|
||||||
|
|
||||||
**Namespace**: `d`
|
**Namespace**: `d`
|
||||||
|
@ -2007,7 +2059,7 @@ Disable C Beautification
|
||||||
|
|
||||||
**Type**: `string`
|
**Type**: `string`
|
||||||
|
|
||||||
**Enum**: `Uncrustify`
|
**Enum**: `Uncrustify` `clang-format`
|
||||||
|
|
||||||
**Description**:
|
**Description**:
|
||||||
|
|
||||||
|
@ -2117,7 +2169,7 @@ Disable C++ Beautification
|
||||||
|
|
||||||
**Type**: `string`
|
**Type**: `string`
|
||||||
|
|
||||||
**Enum**: `Uncrustify`
|
**Enum**: `Uncrustify` `clang-format`
|
||||||
|
|
||||||
**Description**:
|
**Description**:
|
||||||
|
|
||||||
|
@ -3162,7 +3214,7 @@ Disable Objective-C Beautification
|
||||||
|
|
||||||
**Type**: `string`
|
**Type**: `string`
|
||||||
|
|
||||||
**Enum**: `Uncrustify`
|
**Enum**: `Uncrustify` `clang-format`
|
||||||
|
|
||||||
**Description**:
|
**Description**:
|
||||||
|
|
||||||
|
@ -3437,7 +3489,7 @@ Disable Python Beautification
|
||||||
|
|
||||||
**Type**: `string`
|
**Type**: `string`
|
||||||
|
|
||||||
**Enum**: `autopep8`
|
**Enum**: `autopep8` `yapf`
|
||||||
|
|
||||||
**Description**:
|
**Description**:
|
||||||
|
|
||||||
|
@ -5942,6 +5994,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 formatter
|
||||||
|
|
||||||
#### [gherkin - Indent size](#gherkin---indent-size)
|
#### [gherkin - Indent size](#gherkin---indent-size)
|
||||||
|
|
|
@ -54,6 +54,10 @@
|
||||||
{
|
{
|
||||||
"name": "Zhang YANG",
|
"name": "Zhang YANG",
|
||||||
"url": "https://github.com/ProgramFan"
|
"url": "https://github.com/ProgramFan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Daniel Bayley",
|
||||||
|
"url": "https://github.com/danielbayley"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@ -83,6 +87,7 @@
|
||||||
"node-dir": "^0.1.8",
|
"node-dir": "^0.1.8",
|
||||||
"node-uuid": "^1.4.3",
|
"node-uuid": "^1.4.3",
|
||||||
"prettydiff": "^1.12.19",
|
"prettydiff": "^1.12.19",
|
||||||
|
"season": "^5.3.0",
|
||||||
"space-pen": "^5.1.1",
|
"space-pen": "^5.1.1",
|
||||||
"strip-json-comments": "^1.0.2",
|
"strip-json-comments": "^1.0.2",
|
||||||
"temp": "^0.8.3",
|
"temp": "^0.8.3",
|
||||||
|
|
|
@ -6,10 +6,13 @@ module.exports = class JSBeautify extends Beautifier
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
# TODO: Add support for options
|
# TODO: Add support for options
|
||||||
CSS: false
|
_:
|
||||||
LESS: false
|
configPath: true
|
||||||
Sass: false
|
predefinedConfig: true
|
||||||
SCSS: false
|
CSS: true
|
||||||
|
LESS: true
|
||||||
|
Sass: true
|
||||||
|
SCSS: true
|
||||||
}
|
}
|
||||||
|
|
||||||
beautify: (text, language, options) ->
|
beautify: (text, language, options) ->
|
||||||
|
@ -18,16 +21,22 @@ module.exports = class JSBeautify extends Beautifier
|
||||||
|
|
||||||
# Require
|
# Require
|
||||||
Comb = require('csscomb')
|
Comb = require('csscomb')
|
||||||
|
expandHomeDir = require('expand-home-dir')
|
||||||
|
CSON = require('season')
|
||||||
|
|
||||||
config = null
|
config = null
|
||||||
|
try # Load from project config file, throwing error if neither exist
|
||||||
|
project = atom.project.getDirectories()?[0]
|
||||||
try
|
try
|
||||||
# Load from Project's .csscomb.json
|
config = CSON.readFileSync(project?.resolve '.csscomb.cson')
|
||||||
projectConfigPath = atom.project.getDirectories()?[0]?.resolve('.csscomb.json')
|
catch
|
||||||
config = require(projectConfigPath) # Will throw error if does not exist
|
config = require(project?.resolve '.csscomb.json')
|
||||||
catch e
|
catch
|
||||||
# Fallback to csscomb
|
try # Load from custom config
|
||||||
config = Comb.getConfig('csscomb')
|
config = CSON.readFileSync(expandHomeDir options.configPath)
|
||||||
# TODO: Add support to select CSSComb predefined config's name
|
catch
|
||||||
|
# Fallback to [selected] CSScomb predifined config
|
||||||
|
config = Comb.getConfig(options.predefinedConfig)
|
||||||
# console.log('config', config, options)
|
# console.log('config', config, options)
|
||||||
# Configure
|
# Configure
|
||||||
comb = new Comb(config)
|
comb = new Comb(config)
|
||||||
|
|
|
@ -83,4 +83,16 @@ module.exports = {
|
||||||
default: false
|
default: false
|
||||||
description: "If in CSS values leading 0s immediately preceeding \
|
description: "If in CSS values leading 0s immediately preceeding \
|
||||||
a decimal should be removed or prevented."
|
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