mirror of
https://github.com/zoriya/flood.git
synced 2025-12-06 07:16:18 +00:00
Improves eslint rules (#785)
* Switch to airbnb's eslint * Applies automatic fixes * Clean up dependencies * New lint rules * Apply auto fixes * Prettier * Update prettier position in eslint config * Aligns prettier and eslint * Use partial configs for client and server directories * Finalizes eslint config (for now) * Applies all elsint fixes * Removes duplciated config * Fixes build & local dev * Fix CI build
This commit is contained in:
@@ -6,8 +6,8 @@ const prettier = require('prettier');
|
||||
|
||||
const filePattern = `{client,scripts,server,shared}${path.sep}!(assets){${path.sep},}{**${path.sep}*,*}.{js,json,md}`;
|
||||
|
||||
const iterateOverFiles = ({onFileRead}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const iterateOverFiles = ({onFileRead}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
glob(filePattern, (error, files) => {
|
||||
if (error) {
|
||||
reject(Error(error));
|
||||
@@ -19,31 +19,30 @@ const iterateOverFiles = ({onFileRead}) => {
|
||||
const filePath = path.join(process.cwd(), file);
|
||||
const fileContents = fs.readFileSync(filePath, 'utf8');
|
||||
return onFileRead(filePath, fileContents);
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const format = () => {
|
||||
console.log(chalk.reset('Formatting files...'));
|
||||
|
||||
iterateOverFiles({
|
||||
onFileRead: (filePath, fileContents) => {
|
||||
return prettier.resolveConfig(filePath).then(options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath, prettier.format(fileContents, {...options, filepath: filePath}), error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
onFileRead: (filePath, fileContents) =>
|
||||
prettier.resolveConfig(filePath).then(
|
||||
options =>
|
||||
new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath, prettier.format(fileContents, {...options, filepath: filePath}), error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
),
|
||||
})
|
||||
.then(() => {
|
||||
console.log(chalk.green('Done formatting files.'));
|
||||
@@ -58,15 +57,14 @@ const check = () => {
|
||||
console.log(chalk.reset('Checking code formatting...'));
|
||||
|
||||
iterateOverFiles({
|
||||
onFileRead: (filePath, fileContents) => {
|
||||
return prettier.resolveConfig(filePath).then(options => {
|
||||
onFileRead: (filePath, fileContents) =>
|
||||
prettier.resolveConfig(filePath).then(options => {
|
||||
const isCompliant = prettier.check(fileContents, {...options, filepath: filePath});
|
||||
|
||||
if (!isCompliant) {
|
||||
throw filePath;
|
||||
}
|
||||
});
|
||||
},
|
||||
}),
|
||||
})
|
||||
.then(() => {
|
||||
console.log(chalk.green('Done checking files.'));
|
||||
|
||||
Reference in New Issue
Block a user