diff --git a/.babelrc b/.babelrc index 6858a5f6..6d2ee05f 100644 --- a/.babelrc +++ b/.babelrc @@ -1,11 +1,4 @@ { - "presets": [ - "@babel/env", - "@babel/typescript", - "@babel/react" - ], - "plugins": [ - "@babel/plugin-proposal-class-properties", - "@babel/proposal-object-rest-spread" - ] + "presets": ["@babel/env", "@babel/typescript", "@babel/react"], + "plugins": ["@babel/plugin-proposal-class-properties", "@babel/proposal-object-rest-spread"] } diff --git a/.eslintrc.js b/.eslintrc.js index 0a1ba10b..82c77ee7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -59,9 +59,14 @@ module.exports = { overrides: [ { files: ['*.ts', '*.tsx', '**/*.ts', '**/*.tsx'], - extends: ['airbnb-typescript', 'plugin:@typescript-eslint/recommended', 'prettier', 'prettier/@typescript-eslint'], + extends: [ + 'airbnb-typescript', + 'plugin:@typescript-eslint/recommended', + 'prettier', + 'prettier/@typescript-eslint', + ], parserOptions: { - project: './tsconfig.json' + project: './tsconfig.json', }, rules: { 'import/no-extraneous-dependencies': 0, @@ -71,7 +76,7 @@ module.exports = { '@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}], // TODO: Explicit return type '@typescript-eslint/explicit-function-return-type': 0, - "@typescript-eslint/explicit-module-boundary-types": 0, + '@typescript-eslint/explicit-module-boundary-types': 0, // TODO: Re-enable after everything is module '@typescript-eslint/no-var-requires': 0, }, diff --git a/.jsdoc.json b/.jsdoc.json index 43e25e30..a08b7453 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -1,27 +1,25 @@ { - "tags": { - "allowUnknownTags": true, - "dictionaries": ["jsdoc"] - }, - "source": { - "include": ["client", "server", "shared", "package.json", "README.md"], - "includePattern": ".js$", - "excludePattern": "(node_modules/|docs)" - }, - "plugins": [ - "plugins/markdown" - ], - "templates": { - "cleverLinks": false, - "monospaceLinks": true, - "useLongnameInNav": false, - "showInheritedInNav": true - }, - "opts": { - "destination": "./docs/", - "encoding": "utf8", - "private": true, - "recurse": true, - "template": "./node_modules/minami" - } + "tags": { + "allowUnknownTags": true, + "dictionaries": ["jsdoc"] + }, + "source": { + "include": ["client", "server", "shared", "package.json", "README.md"], + "includePattern": ".js$", + "excludePattern": "(node_modules/|docs)" + }, + "plugins": ["plugins/markdown"], + "templates": { + "cleverLinks": false, + "monospaceLinks": true, + "useLongnameInNav": false, + "showInheritedInNav": true + }, + "opts": { + "destination": "./docs/", + "encoding": "utf8", + "private": true, + "recurse": true, + "template": "./node_modules/minami" + } } diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..a65ad2a8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,9 @@ +# Hidden folders +.*/ + +# Markdown and HTML +*.md +*.html + +# Distribution files +dist/ diff --git a/config.cli.js b/config.cli.js index 545139ca..d7ada4fc 100644 --- a/config.cli.js +++ b/config.cli.js @@ -108,7 +108,7 @@ const {argv} = require('yargs') if (argv.rtorrent) { const rTorrentProcess = spawn('rtorrent', ['-o', 'system.daemon.set=true']); process.on('exit', () => { - console.log('Killing rTorrent daemon...') + console.log('Killing rTorrent daemon...'); rTorrentProcess.kill('SIGTERM'); }); } diff --git a/package.json b/package.json index 5de83f43..024db517 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "build-docs": "jsdoc -c ./.jsdoc.json", "build-i18n": "formatjs compile --ast --format simple client/src/javascript/i18n/strings.json --out-file client/src/javascript/i18n/strings.compiled.json && formatjs compile-folder --ast --format simple client/src/javascript/i18n/translations client/src/javascript/i18n/compiled", "deprecated-warning": "node client/scripts/deprecated-warning.js && sleep 10", - "format-source": "node scripts/prettier.js formatSource", + "format-source": "prettier -w .", "check-compiled-i18n": "npm run build-i18n && npm run format-source && git diff --quiet client/src/javascript/i18n/compiled", - "check-source-formatting": "node scripts/prettier.js check", + "check-source-formatting": "prettier -c .", "check-types": "tsc", "lint": "NODE_ENV=development eslint --max-warnings 0 . --ext .js --ext .jsx --ext .ts --ext .tsx", "prepack": "rm -rf dist && npm run build", diff --git a/scripts/prettier.js b/scripts/prettier.js index 2e705bbf..d8b1607f 100644 --- a/scripts/prettier.js +++ b/scripts/prettier.js @@ -1,11 +1,6 @@ -const chalk = require('chalk'); const fs = require('fs'); -const glob = require('glob'); -const path = require('path'); const prettier = require('prettier'); -const SOURCE_PATTERN = `{client,scripts,server,shared}${path.sep}!(assets){${path.sep},}{**${path.sep}*,*}.{js,jsx,ts,tsx,json,md,css,scss,sass,less}`; - const readFile = (filePath) => { return new Promise((resolve, reject) => { fs.readFile(filePath, 'utf8', (error, fileContent) => { @@ -43,64 +38,6 @@ const formatFile = async (inputFilePath, outputFilePath) => { return writtenFilePath; }; -const getSourceFilePaths = () => { - return new Promise((resolve, reject) => { - glob(SOURCE_PATTERN, (error, files) => { - if (error) { - reject(error); - return; - } - - resolve(files.map((filePath) => path.join(process.cwd(), filePath))); - }); - }); -}; - -const formatSource = async () => { - console.log(chalk.reset('Formatting source files...')); - - try { - const sourceFilePaths = await getSourceFilePaths(); - const formattedPaths = await Promise.all(sourceFilePaths.map((filePath) => formatFile(filePath, filePath))); - - console.log(chalk.green(`Formatted ${formattedPaths.length} files.`)); - } catch (error) { - console.log(chalk.red('Problem formatting file:\n'), chalk.reset(error)); - process.exit(1); - } -}; - -const check = async () => { - console.log(chalk.reset('Validating source file formatting...')); - - try { - const sourceFilePaths = await getSourceFilePaths(); - await Promise.all( - sourceFilePaths.map(async (filePath) => { - const fileContent = await readFile(filePath); - const prettierConfig = await prettier.resolveConfig(filePath); - const isCompliant = prettier.check(fileContent, {...prettierConfig, filepath: filePath}); - - if (!isCompliant) { - throw filePath; - } - }), - ); - - console.log(chalk.green('Finished validating file formatting.')); - } catch (error) { - console.log(chalk.red('Unformatted file found:\n'), chalk.reset(error)); - process.exit(1); - } -}; - -const commands = {check, formatSource}; -const desiredCommand = process.argv.slice(2)[0]; - -if (commands[desiredCommand] != null) { - commands[desiredCommand](); -} - module.exports = { formatFile, };