Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CSScomb support #623

Merged
merged 1 commit into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 111 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -2007,7 +2059,7 @@ Disable C Beautification

**Type**: `string`

**Enum**: `Uncrustify`
**Enum**: `Uncrustify` `clang-format`

**Description**:

Expand Down Expand Up @@ -2117,7 +2169,7 @@ Disable C++ Beautification

**Type**: `string`

**Enum**: `Uncrustify`
**Enum**: `Uncrustify` `clang-format`

**Description**:

Expand Down Expand Up @@ -3162,7 +3214,7 @@ Disable Objective-C Beautification

**Type**: `string`

**Enum**: `Uncrustify`
**Enum**: `Uncrustify` `clang-format`

**Description**:

Expand Down Expand Up @@ -3437,7 +3489,7 @@ Disable Python Beautification

**Type**: `string`

**Enum**: `autopep8`
**Enum**: `autopep8` `yapf`

**Description**:

Expand Down Expand Up @@ -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 - Indent size](#gherkin---indent-size)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
{
"name": "Zhang YANG",
"url": "https://github.com/ProgramFan"
},
{
"name": "Daniel Bayley",
"url": "https://github.com/danielbayley"
}
],
"engines": {
Expand Down Expand Up @@ -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",
Expand Down
33 changes: 21 additions & 12 deletions src/beautifiers/csscomb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change:

    CSS: true
    LESS: true
    Sass: true
    SCSS: true

to:

    _:
      configPath: true
      predefinedConfig: true
    CSS: true
    LESS: true
    Sass: true
    SCSS: true

Similar to https://github.com/danielbayley/atom-beautify/blob/master/src/beautifiers/prettydiff.coffee#L6

This allows only the options that are supported (configPath and predefinedConfig) and puts that for the default (_).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the last thing that needs fixing. Right now it looks like all options are available, when it should be only configPath and predefinedConfig option. After that, re-run coffee docs/ to generate the correct documentation with only the allowed options. Thanks!

LESS: true
Sass: true
SCSS: true
}

beautify: (text, language, options) ->
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/languages/css.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}