Skip to content

Commit 4b26392

Browse files
committed
Add .editorconfig and fixup mixed indentation
1 parent efdf2e6 commit 4b26392

File tree

2 files changed

+76
-61
lines changed

2 files changed

+76
-61
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Config helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
indent_style = tab
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

autoload/node/lib.vim

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client",
1919
"
2020
" require(a:name) from module at path a:from
2121
" 1. If a:name is a core module,
22-
" a. return the core module
23-
" b. STOP
22+
" a. return the core module
23+
" b. STOP
2424
" 2. If a:name begins with '/'
25-
" a. set a:from to be the filesystem root
25+
" a. set a:from to be the filesystem root
2626
" 3. If a:name begins with './' or '/' or '../'
27-
" a. LOAD_AS_FILE(a:from + a:name)
28-
" b. LOAD_AS_DIRECTORY(a:from + a:name)
27+
" a. LOAD_AS_FILE(a:from + a:name)
28+
" b. LOAD_AS_DIRECTORY(a:from + a:name)
2929
" 4. LOAD_NODE_MODULES(a:name, dirname(a:from))
3030
" 5. THROW "not found"
3131
function! node#lib#find(name, from)
@@ -36,24 +36,24 @@ function! node#lib#find(name, from)
3636
return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js"
3737
endif
3838

39-
let request = s:getModulePath(a:name, a:from)
40-
if !empty(request)
41-
let asFile = s:loadAsFile(request)
42-
if !empty(asFile) | return asFile | endif
39+
let request = s:getModulePath(a:name, a:from)
40+
if !empty(request)
41+
let asFile = s:loadAsFile(request)
42+
if !empty(asFile) | return asFile | endif
4343

44-
let asDirectory = s:loadAsDirectory(request)
45-
if !empty(asDirectory) | return asDirectory | endif
46-
endif
44+
let asDirectory = s:loadAsDirectory(request)
45+
if !empty(asDirectory) | return asDirectory | endif
46+
endif
4747

48-
let asNodeModule = s:loadNodeModules(a:name, s:dirname(a:from))
48+
let asNodeModule = s:loadNodeModules(a:name, s:dirname(a:from))
4949
if !empty(asNodeModule) | return asNodeModule | endif
5050
endfunction
5151

5252
" LOAD_AS_FILE(X)
53-
" 1. If X is a file, load X as JavaScript text. STOP
54-
" 2. If X.js is a file, load X.js as JavaScript text. STOP
55-
" 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
56-
" 4. If X.node is a file, load X.node as binary addon. STOP
53+
" 1. If X is a file, load X as JavaScript text. STOP
54+
" 2. If X.js is a file, load X.js as JavaScript text. STOP
55+
" 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
56+
" 4. If X.node is a file, load X.node as binary addon. STOP
5757
function! s:loadAsFile(path)
5858
if a:path !~# '\v/(\.\.?/?)?$'
5959
let path_with_suffix = s:resolveSuffix(a:path)
@@ -62,19 +62,19 @@ function! s:loadAsFile(path)
6262
endfunction
6363

6464
" LOAD_INDEX(X)
65-
" 1. If X/index.js is a file, load X/index.js as JavaScript text. STOP
65+
" 1. If X/index.js is a file, load X/index.js as JavaScript text. STOP
6666
" 2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
67-
" 3. If X/index.node is a file, load X/index.node as binary addon. STOP
67+
" 3. If X/index.node is a file, load X/index.node as binary addon. STOP
6868
function! s:loadIndex(path)
6969
return s:resolveSuffix(a:path . "/index")
7070
endfunction
7171

7272
" LOAD_AS_DIRECTORY(X)
7373
" 1. If X/package.json is a file,
74-
" a. Parse X/package.json, and look for "main" field.
75-
" b. let M = X + (json main field)
76-
" c. LOAD_AS_FILE(M)
77-
" d. LOAD_INDEX(M)
74+
" a. Parse X/package.json, and look for "main" field.
75+
" b. let M = X + (json main field)
76+
" c. LOAD_AS_FILE(M)
77+
" d. LOAD_INDEX(M)
7878
" 2. LOAD_INDEX(X)
7979
function! s:loadAsDirectory(path)
8080
" Node.js checks for package.json in every directory, not just the
@@ -89,10 +89,10 @@ function! s:loadAsDirectory(path)
8989

9090
if !empty(main) && main != ""
9191
let path = a:path . "/" . main
92-
let asFile = s:loadAsFile(path)
92+
let asFile = s:loadAsFile(path)
9393
if !empty(asFile) | return asFile | endif
9494

95-
let asIndex = s:loadIndex(path)
95+
let asIndex = s:loadIndex(path)
9696
if !empty(asIndex) | return asIndex | endif
9797
endif
9898
endif
@@ -103,54 +103,54 @@ endfunction
103103
" LOAD_NODE_MODULES(X, START)
104104
" 1. let DIRS=NODE_MODULES_PATHS(START)
105105
" 2. for each DIR in DIRS:
106-
" a. LOAD_AS_FILE(DIR/X)
107-
" b. LOAD_AS_DIRECTORY(DIR/X)
106+
" a. LOAD_AS_FILE(DIR/X)
107+
" b. LOAD_AS_DIRECTORY(DIR/X)
108108
function! s:loadNodeModules(x, start)
109-
let dirs = s:nodeModulePaths(a:start)
110-
for dir in dirs
109+
let dirs = s:nodeModulePaths(a:start)
110+
for dir in dirs
111111
let path = dir . "/" . a:x
112-
let asFile = s:loadAsFile(path)
112+
let asFile = s:loadAsFile(path)
113113
if !empty(asFile) | return asFile | endif
114114

115-
let asDirectory = s:loadAsDirectory(path)
115+
let asDirectory = s:loadAsDirectory(path)
116116
if !empty(asDirectory) | return asDirectory | endif
117-
endfor
117+
endfor
118118
endfunction
119119

120120
" NODE_MODULES_PATHS(START)
121121
" 1. let PARTS = path split(START)
122122
" 2. let I = count of PARTS - 1
123123
" 3. let DIRS = []
124124
" 4. while I >= 0,
125-
" a. if PARTS[I] = "node_modules" CONTINUE
126-
" b. DIR = path join(PARTS[0 .. I] + "node_modules")
127-
" c. DIRS = DIRS + DIR
128-
" d. let I = I - 1
125+
" a. if PARTS[I] = "node_modules" CONTINUE
126+
" b. DIR = path join(PARTS[0 .. I] + "node_modules")
127+
" c. DIRS = DIRS + DIR
128+
" d. let I = I - 1
129129
" 5. return DIRS
130130
function! s:nodeModulePaths(start)
131-
let parts = split(a:start, '/')
132-
133-
" We want to keep the leading slash of an absolute path
134-
if a:start =~# s:ABSPATH
135-
let parts[0] = '/' . parts[0]
136-
endif
137-
138-
let i = len(parts) - 1
139-
let dirs = []
140-
while i >= 0
141-
if parts[i] == 'node_modules' | continue | endif
142-
let dir = join(parts[0:i] + ['node_modules'], '/')
143-
let dirs += [dir]
144-
let i = i - 1
145-
endwhile
146-
147-
" Add support for NODE_PATH
148-
let NODE_PATH = $NODE_PATH
149-
if !empty(NODE_PATH)
150-
let dirs += [NODE_PATH]
151-
endif
152-
153-
return dirs
131+
let parts = split(a:start, '/')
132+
133+
" We want to keep the leading slash of an absolute path
134+
if a:start =~# s:ABSPATH
135+
let parts[0] = '/' . parts[0]
136+
endif
137+
138+
let i = len(parts) - 1
139+
let dirs = []
140+
while i >= 0
141+
if parts[i] == 'node_modules' | continue | endif
142+
let dir = join(parts[0:i] + ['node_modules'], '/')
143+
let dirs += [dir]
144+
let i = i - 1
145+
endwhile
146+
147+
" Add support for NODE_PATH
148+
let NODE_PATH = $NODE_PATH
149+
if !empty(NODE_PATH)
150+
let dirs += [NODE_PATH]
151+
endif
152+
153+
return dirs
154154
endfunction
155155

156156
function! s:getModulePath(name, from)
@@ -159,11 +159,11 @@ function! s:getModulePath(name, from)
159159
elseif a:name =~# s:RELPATH
160160
let dir = isdirectory(a:from) ? a:from : s:dirname(a:from)
161161
return dir . "/" . a:name
162-
endif
162+
endif
163163
endfunction
164164

165165
function! s:dirname(path)
166-
return fnamemodify(a:path, ':h')
166+
return fnamemodify(a:path, ':h')
167167
endfunction
168168

169169
function! node#lib#version()

0 commit comments

Comments
 (0)