2.0.0 • Published 8 months ago

editorconfig v2.0.0

Weekly downloads
2,165,028
License
MIT
Repository
github
Last release
8 months ago

EditorConfig JavaScript Core

Tests Coverage Status

The EditorConfig JavaScript core will provide the same functionality as the EditorConfig C Core and EditorConfig Python Core.

Installation

You need node to use this package.

To install the package locally:

$ npm install editorconfig

To install the package system-wide:

$ npm install -g editorconfig

Usage

Options

Most of the API takes an options object, which has the following defaults:

{
  config: '.editorconfig',
  version: pkg.version,
  root: '/',
  files: undefined,
  cache: undefined,
};

in Node.js:

parse(filePath, options)

Search for .editorconfig files starting from the current directory to the root directory. Combine all of the sections whose section names match filePath into a single object.

Example:

const editorconfig = require('editorconfig');
const path = require('path');

const filePath = path.join(__dirname, 'sample.js');

(async () => {
  console.log(await editorconfig.parse(filePath, {files: []}));
})();
/*
  {
    indent_style: 'space',
    indent_size: 2,
    end_of_line: 'lf',
    charset: 'utf-8',
    trim_trailing_whitespace: true,
    insert_final_newline: true,
    tab_width: 2
  };
  assert.deepEqual(files, [
    { fileName: '[DIRECTORY]/.editorconfig', glob: '*' },
    { fileName: '[DIRECTORY]/.editorconfig', glob: '*.js' }
  ])
*/

parseSync(filePath, options)

Synchronous version of editorconfig.parse().

parseBuffer(fileContent)

The parse() function above uses parseBuffer() under the hood. If you have the contents of a config file, and want to see what is being processed for just that file rather than the full directory hierarchy, this might be useful.

parseString(fileContent)

This is a thin wrapper around parseBuffer() for backward-compatibility. Prefer parseBuffer() to avoid an unnecessary UTF8-to-UTF16-to-UTF8 conversion. Deprecated.

parseFromFiles(filePath, configs, options)

Low-level interface, which exists only for backward-compatibility. Deprecated.

Example:

const editorconfig = require('editorconfig');
const fs = require('fs');
const path = require('path');

const configPath = path.join(__dirname, '.editorconfig');
const configs = [
  {
    name: configPath,
    contents: fs.readFileSync(configPath, 'utf8')
  }
];

const filePath = path.join(__dirname, '/sample.js');

(async () => {
  console.log(await editorconfig.parseFromFiles(filePath, Promise.resolve(configs)))
})();
/*
  {
    indent_style: 'space',
    indent_size: 2,
    end_of_line: 'lf',
    charset: 'utf-8',
    trim_trailing_whitespace: true,
    insert_final_newline: true,
    tab_width: 2
  };
*/

parseFromFilesSync(filePath, configs, options)

Synchronous version of editorconfig.parseFromFiles(). Deprecated.

in Command Line

$ ./bin/editorconfig

Usage: editorconfig [options] <FILEPATH...>

Arguments:
  FILEPATH       Files to find configuration for.  Can be a hyphen (-) if you
                 want path(s) to be read from stdin.

Options:
  -v, --version  Display version information from the package
  -f <path>      Specify conf filename other than '.editorconfig'
  -b <version>   Specify version (used by devs to test compatibility)
  --files        Output file names that contributed to the configuration,
                 rather than the configuation itself
  -h, --help     display help for command

Example:

$ ./bin/editorconfig /home/zoidberg/humans/anatomy.md
charset=utf-8
insert_final_newline=true
end_of_line=lf
tab_width=8
trim_trailing_whitespace=sometimes
$ ./bin/editorconfig --files /home/zoidberg/humans/anatomy.md
/home/zoidberg/.editorconfig [*]
/home/zoidberg/.editorconfig [*.md]
/home/zoidberg/humans/.editorconfig [*]

Development

To install dependencies for this package run this in the package directory:

$ npm install

Next, run the following commands:

$ npm run build
$ npm link

The global editorconfig will now point to the files in your development repository instead of a globally-installed version from npm. You can now use editorconfig directly to test your changes.

If you ever update from the central repository and there are errors, it might be because you are missing some dependencies. If that happens, just run npm link again to get the latest dependencies.

To test the command line interface:

$ editorconfig <filepath>

Testing

CMake must be installed to run the tests.

To run the tests:

$ npm test

To run the tests with increased verbosity (for debugging test failures):

$ npm run ci
js-beautifywindego-js-beautifyexpo-template-stack-navigatorexpo-template-bottom-navigatorexpo-template-default@olivervorasai/sliderworklio-cli@fellwork/eslint-shared@infinitebrahmanuniverse/nolb-edirenovate@everything-registry/sub-chunk-1554lint-staged-editorconfiglint-trapkafirchain-tetrislintspaceshot-zone-vuemarko-prettyprintmgssservermrm-corejs-beautify-ejsxjs-beautify-jsreportjs-beautify-nahidjs-beautify-temp-fixjs-beautify2js-beautify-with-blademethane-plugin-editorconfignodetextpublicnodejshahamaucash-clieditorconfig-clieditorconfig-linteditorconfig-toolseditorconfig-validateeditorconfig-get-indenteclintdts-packgenerator-xes-bdfgenerator-spritesmithgenerator-cfsgexpressful-scriptseslint-plugin-editorconfigquick-releaseorganize-imports-cliprettierxprettierx2playship-pirate-fight@havenmoney/organize-imports-cli@iamjinhyoungjoo/skku-statvite_vue3_ts_ssssdddddyyyyvue-size-trackertransynctravisci-npm-deploytypescript-formatter@kenyerman/i18lintyaimdlinksyessve-md-links@netatwork/aurelia-lint@lorena_alvarez/md-links@nkt/stylefmtsharec-editorconfig-hookslush-my-stylestylefmtstylefmt--pr-320superfe-hn-inspectorsuperfe-rn-inspectorswagger-schematicsstarfiresportslotto-tile-testspaceconfrootnovaterenovate-csm@object-studio/react-native-web@marko/prettyprint@poppinss/mrm-core@valespring/code-config@valespring/valespring-code-config@vegansk/typescript-formatter@theia/editorconfig@tillig/json-sort-cli@tonysusi/vapid@prettyio/pretty@prettier-x/formatter-2021-01@pnb/eslint@ronilaukkarinen/stylefmt@stencil-tools/generator@techsky/eslint-configalm@wiptheia/editorconfig@zokugun/artifact@xiamx/typescript-formatterbeautify-less@akashic/akashic-cli-commonsastridtimana-md-links@azimutlabs/eslint-env@axellero/eslint-env@artsurkan/stylefmt@ckatzorke/renovatebrave-mouse@bmewburn/js-beautifycabin-service-cli
1.0.4

8 months ago

1.0.3

9 months ago

2.0.0

9 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.15.3

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.15.0

6 years ago

0.14.2

6 years ago

0.14.1

7 years ago

0.14.0

7 years ago

0.13.3

7 years ago

0.13.2

8 years ago

0.13.1

8 years ago

0.13.0

8 years ago

0.12.2

9 years ago

0.12.1

9 years ago

0.12.0

9 years ago

0.11.4

11 years ago

0.11.3

11 years ago

0.11.2

11 years ago

0.11.1

11 years ago

0.11.0

11 years ago