Skip to content

Commit a33712a

Browse files
committed
refs #55: uses traditional ".py" in python3 filename.
Signed-off-by: Eric Wang <[email protected]>
1 parent 54256e2 commit a33712a

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

Diff for: lib/helper.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ function getUnit(units, v) {
3030
}
3131

3232
var LANGS = [
33-
{lang: 'bash', ext: '.sh', style: '#'},
34-
{lang: 'c', ext: '.c', style: 'c'},
35-
{lang: 'cpp', ext: '.cpp', style: 'c'},
36-
{lang: 'csharp', ext: '.cs', style: 'c'},
37-
{lang: 'golang', ext: '.go', style: 'c'},
38-
{lang: 'java', ext: '.java', style: 'c'},
39-
{lang: 'javascript', ext: '.js', style: 'c'},
40-
{lang: 'kotlin', ext: '.kt', style: 'c'},
41-
{lang: 'mysql', ext: '.sql', style: '#'},
42-
{lang: 'python', ext: '.py', style: '#'},
43-
{lang: 'python3', ext: '.py3', style: '#'},
44-
{lang: 'ruby', ext: '.rb', style: '#'},
45-
{lang: 'scala', ext: '.scala', style: 'c'},
46-
{lang: 'swift', ext: '.swift', style: 'c'}
33+
{lang: 'bash', ext: '.sh', style: '#'},
34+
{lang: 'c', ext: '.c', style: 'c'},
35+
{lang: 'cpp', ext: '.cpp', style: 'c'},
36+
{lang: 'csharp', ext: '.cs', style: 'c'},
37+
{lang: 'golang', ext: '.go', style: 'c'},
38+
{lang: 'java', ext: '.java', style: 'c'},
39+
{lang: 'javascript', ext: '.js', style: 'c'},
40+
{lang: 'kotlin', ext: '.kt', style: 'c'},
41+
{lang: 'mysql', ext: '.sql', style: '#'},
42+
{lang: 'python', ext: '.py', style: '#'},
43+
{lang: 'python3', ext: '.python3.py', style: '#'},
44+
{lang: 'ruby', ext: '.rb', style: '#'},
45+
{lang: 'scala', ext: '.scala', style: 'c'},
46+
{lang: 'swift', ext: '.swift', style: 'c'}
4747
];
4848

4949
var h = {};
@@ -130,11 +130,18 @@ h.langToExt = function(lang) {
130130
};
131131

132132
h.extToLang = function(fullpath) {
133-
var ext = path.extname(fullpath);
134-
var res = _.find(LANGS, function(x) {
135-
return x.ext === ext;
136-
});
137-
return res ? res.lang : 'unknown';
133+
// HACK: compatible with old ext
134+
if (fullpath.endsWith('.py3')) return 'python3';
135+
136+
var res = _.chain(LANGS)
137+
.filter(function(x) {
138+
return fullpath.endsWith(x.ext);
139+
})
140+
.sortBy(function(x) {
141+
return -x.ext.length;
142+
})
143+
.value();
144+
return res.length ? res[0].lang : 'unknown';
138145
};
139146

140147
h.langToCommentStyle = function(lang) {

Diff for: test/test_helper.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('helper', function() {
119119
assert.equal(h.langToExt('javascript'), '.js');
120120
assert.equal(h.langToExt('mysql'), '.sql');
121121
assert.equal(h.langToExt('python'), '.py');
122-
assert.equal(h.langToExt('python3'), '.py3');
122+
assert.equal(h.langToExt('python3'), '.python3.py');
123123
assert.equal(h.langToExt('ruby'), '.rb');
124124
assert.equal(h.langToExt('scala'), '.scala');
125125
assert.equal(h.langToExt('swift'), '.swift');
@@ -138,6 +138,7 @@ describe('helper', function() {
138138
assert.equal(h.extToLang('c:/file.js'), 'javascript');
139139
assert.equal(h.extToLang('c:/Users/skygragon/file.py'), 'python');
140140
assert.equal(h.extToLang('c:/Users/skygragon/file.py3'), 'python3');
141+
assert.equal(h.extToLang('c:/Users/skygragon/file.python3.py'), 'python3');
141142
assert.equal(h.extToLang('~/file.rb'), 'ruby');
142143
assert.equal(h.extToLang('/tmp/file.scala'), 'scala');
143144
assert.equal(h.extToLang('~/leetcode/file.swift'), 'swift');

0 commit comments

Comments
 (0)