style: fix code style

This commit is contained in:
Gajus Kuizinas
2016-11-01 15:26:29 +00:00
parent 7990da993f
commit 858085656b
17 changed files with 320 additions and 321 deletions
+44 -44
View File
@@ -1,81 +1,81 @@
import fs from 'fs';
import _ from 'lodash';
import path from 'path';
import _ from 'lodash';
import validateTargetDirectory from './validateTargetDirectory';
const hasIndex = (directoryPath) => {
const indexPath = path.resolve(directoryPath, 'index.js');
const indexPath = path.resolve(directoryPath, 'index.js');
try {
fs.statSync(indexPath);
try {
fs.statSync(indexPath);
return true;
} catch (error) {
return false;
}
return true;
} catch (error) {
return false;
}
};
const hasNoExtension = (fileName) => {
const matches = fileName.match(/\./g);
const matches = fileName.match(/\./g);
return !matches;
return !matches;
};
const hasMultipleExtensions = (fileName) => {
const matches = fileName.match(/\./g);
const matches = fileName.match(/\./g);
return matches && matches.length > 1;
return matches && matches.length > 1;
};
const isSafeName = (fileName) => {
return /^[a-z][a-z0-9\._]+$/i.test(fileName);
return /^[a-z][a-z0-9._]+$/i.test(fileName);
};
const removeDuplicates = (files) => {
return _.filter(files, (fileName) => {
return !_.includes(files, fileName + '.js');
});
return _.filter(files, (fileName) => {
return !_.includes(files, fileName + '.js');
});
};
export default (directoryPath) => {
let children;
let children;
validateTargetDirectory(directoryPath);
validateTargetDirectory(directoryPath);
children = fs.readdirSync(directoryPath);
children = fs.readdirSync(directoryPath);
children = _.filter(children, (fileName) => {
const absolutePath = path.resolve(directoryPath, fileName);
const isDirectory = fs.statSync(absolutePath).isDirectory();
children = _.filter(children, (fileName) => {
const absolutePath = path.resolve(directoryPath, fileName);
const isDirectory = fs.statSync(absolutePath).isDirectory();
if (!isSafeName(fileName)) {
return false;
}
if (!isSafeName(fileName)) {
return false;
}
if (hasNoExtension(fileName) && !isDirectory) {
return false;
}
if (hasNoExtension(fileName) && !isDirectory) {
return false;
}
if (hasMultipleExtensions(fileName)) {
return false;
}
if (hasMultipleExtensions(fileName)) {
return false;
}
if (_.startsWith(fileName, 'index.js')) {
return false;
}
if (_.startsWith(fileName, 'index.js')) {
return false;
}
if (!isDirectory && !_.endsWith(fileName, '.js')) {
return false;
}
if (!isDirectory && !_.endsWith(fileName, '.js')) {
return false;
}
if (isDirectory && !hasIndex(absolutePath)) {
return false;
}
if (isDirectory && !hasIndex(absolutePath)) {
return false;
}
return true;
});
return true;
});
children = removeDuplicates(children);
children = removeDuplicates(children);
return children.sort();
return children.sort();
};