8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EditorConfigで心の健康を保とう

Last updated at Posted at 2018-01-17

EditorConfigとは

エンジニアの心の健康を保つのに有効なもの。

ざっくり言うと、コードのスタイルを統一するためのエディタ横断プラグイン

.editorconfigというファイルを置けば、記載されたconfigに基づいて文字コードや改行コード、インデントサイズやインデントスタイルを自動で直してくれる優しいやつ。

EditorConfigを利用することで、

  • プロジェクト移動するときエディタの設定いじるのめんどい問題
  • そもそも細かいコード規約までexcelやスプレッドシートで管理するのつらい問題
  • インデントスタイルはtabなのかspaceなのか問題
  • インデントサイズは2つなのか4つなのか問題
  • ファイルごとに改行コードが違う問題
  • コードレビュー時に超どうでもいいこと(行末に無駄なspaceあるよなど)を指摘する時間が勿体無い問題

以上の悲しみに溢れる不毛な争いを根絶できる。

参考リンク(というかこっち見ればこの記事見ないでも良い気もする)

sublime,vimにおけるインストール方法

たまたま身の回りにsublime派とvim派しかいないのでそれぞれのインストール方法を書いておく。

先ほど挙げたqiitaの記事を見れば大体わかると思うが一応補足として。

.vimrc
NeoBundle 'editorconfig/editorconfig-vim'
  • 追記後Vim立ち上げて:NeoBundleInstall

補足:vim使ってるけどneobundleとか全然よくわかんない人用

もう全然わかんないしvimrcなんて書き換えたことないvimmer向け手順

  • neobundleのインストール(mac向け。windowsはごめんなさい)
$ mkdir -p ~/.vim/bundle
$ cd ~/.vim/bundle
$ git clone git://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim
  • .vimrcの記述
$ vim ~/.vimrc

以下の内容をペースト(余計なものも入ってるけど気にしないで)

.vimrc
:set clipboard=unnamed
:syntax on
set nocompatible
filetype off            " for NeoBundle

if has('vim_starting')
        set rtp+=$HOME/.vim/bundle/neobundle.vim/
endif
call neobundle#begin(expand('~/.vim/bundle'))
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'editorconfig/editorconfig-vim'
call neobundle#end()

filetype plugin indent on       " restore filetype
  • bundleのインストール
$ vim
:NeoBundleInstall

.editorconfigファイルの一例

  • このファイルをプロジェクトのリポジトリに置いておけばpullした人のエディタに自動的に適用される
  • 今回はphpしか扱わないプロジェクトに利用したので、php用しか書いてない。
  • 拡張子ごとに設定を記述できるので、jsの場合はindent_size2とかも追記できる。
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

これで世界の平和は保たれた。

やったね!!!!!!!!!!!

8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?