diff --git a/docs/options.md b/docs/options.md index 60d26b9..ad651ea 100644 --- a/docs/options.md +++ b/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` @@ -2007,7 +2059,7 @@ Disable C Beautification **Type**: `string` -**Enum**: `Uncrustify` +**Enum**: `Uncrustify` `clang-format` **Description**: @@ -2117,7 +2169,7 @@ Disable C++ Beautification **Type**: `string` -**Enum**: `Uncrustify` +**Enum**: `Uncrustify` `clang-format` **Description**: @@ -3162,7 +3214,7 @@ Disable Objective-C Beautification **Type**: `string` -**Enum**: `Uncrustify` +**Enum**: `Uncrustify` `clang-format` **Description**: @@ -3437,7 +3489,7 @@ Disable Python Beautification **Type**: `string` -**Enum**: `autopep8` +**Enum**: `autopep8` `yapf` **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 - Indent size](#gherkin---indent-size) diff --git a/package.json b/package.json index 2208cd5..d35ae14 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/beautifiers/csscomb.coffee b/src/beautifiers/csscomb.coffee index 7519fe0..869997c 100644 --- a/src/beautifiers/csscomb.coffee +++ b/src/beautifiers/csscomb.coffee @@ -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) diff --git a/src/languages/css.coffee b/src/languages/css.coffee index 46eae80..87419c6 100644 --- a/src/languages/css.coffee +++ b/src/languages/css.coffee @@ -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"] }