GithubHelp home page GithubHelp logo

isabella232 / editorconfig-core-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from editorconfig/editorconfig-core-ruby

0.0 0.0 0.0 57 KB

Clone of EditorConfig core written in Ruby

License: MIT License

Ruby 100.00%

editorconfig-core-ruby's Introduction

EditorConfig Ruby Core

Build Status

EditorConfig Ruby Core provides the same functionality as the EditorConfig C Core and EditorConfig Python Core libraries.

EditorConfig Project

EditorConfig makes it easy to maintain the correct coding style when switching between different text editors and between different projects. The EditorConfig project maintains a file format and plugins for various text editors which allow this file format to be read and used by those editors. For information on the file format and supported text editors, see the EditorConfig website.

Installation

With RubyGems:

$ gem install editorconfig

Usage

Loading library module.

require 'editor_config'
EditorConfig.parse(File.read(".editorconfig"))

A command line binary is also provided.

$ editorconfig main.c
charset=utf-8
insert_final_newline=true
end_of_line=lf
tab_width=8

Load

File System

An flattened config can be loaded from the file system with:

filename = "~/Project/foo/lib/foo.rb"
config = EditorConfig.load_file(filename)

# config: hash of properties and values
{
  "charset" => "utf-8",
  "indent_style" => "space",
  "end_of_line" => "lf",
  "insert_final_newline" => "true"
}

This API walks up the directory hierarchy gathering all .editorconfig files until it reaches a config that defines root = true.

Custom Loader

A custom loader can be provided to read files from another source rather than the file system.

For an example, you might load files directly from a git repository.

tree_sha, filename = "348b1ea52f897f313d62c56c2ba785a41f654861", "lib/foo.rb"

config = EditorConfig.load(filename) do |config_path|
  if blob_sha = `git ls-tree #{tree_sha} #{config_path}`.split(" ")[2]
    `git cat-file blob #{blob_sha}`
  end
end

Parse

A low-level API for parsing an individual .editorconfig file.

A [config, root] tuple is returned. The root bit is set if a top-level root = true is seen. The config value is a two dimensional hash mapping section names to property names and values.

data = File.read(".editorconfig")
config, root = EditorConfig.parse(data)

# root: if top-most root = true flag is set
true

# config: hash of sections and properties
{
  "*" => {
    "end_of_line" => "lf",
    "insert_final_newline" => "true"
  },
  "*.{js,py}" => {
    "charset" => "utf-8"
  }
}

Testing

Cmake is required to run the test suite. On OSX, just brew install cmake.

Then run the tests with:

$ rake test

editorconfig-core-ruby's People

Contributors

josh avatar brianmario avatar nicolasleger avatar bkeepers avatar danielromero avatar florianb avatar stephengroat avatar treyhunner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.