From ee5217a9d2f274a1e614b77ee98226edd5163406 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Mon, 15 Jul 2019 10:40:58 +0200 Subject: [PATCH] Fix eslint/prettier integration --- .editorconfig | 3 +++ .eslintrc.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ .prettierrc | 1 + package.json | 22 ++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .prettierrc create mode 100644 package.json diff --git a/.editorconfig b/.editorconfig index 9d5481a..9097566 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,9 @@ charset=utf-8 trim_trailing_whitespace=true insert_final_newline=true +[{*.js,*.jsx}] +indent_size=2 + [{*.yml,*.yaml}] indent_size=2 diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..6ae271c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,63 @@ +/* eslint-disable import/no-commonjs, import/unambiguous */ +/* global module:false, __dirname:false */ + +const path = require('path'); +const fs = require('fs'); +const {execSync} = require('child_process'); +const _ = require('lodash'); +const resolve = require('resolve'); +const yaml = require('js-yaml'); + +// Returns the path to the Indico source package/repo +const PATH_COMMAND = `python -c 'from flask.helpers import get_root_path; print get_root_path("indico")'`; + +let indicoBaseDir = null; +const indicoPathFile = path.join(__dirname, '.indico_source'); + +// If there's an .indico_source file in the same dir, let's use it +if (fs.existsSync(indicoPathFile)) { + indicoBaseDir = fs + .readFileSync(indicoPathFile) + .toString() + .trim(); +} + +// Otherwise, let's use Python to figure it out +if (!indicoBaseDir) { + // Figure out where the Indico code base has been set up + indicoBaseDir = path.join( + execSync(PATH_COMMAND, { + encoding: 'utf8', + }).trim(), + '..' + ); +} + +let currentMap = []; +let defaultConfig = {}; + +try { + defaultConfig = yaml.safeLoad(fs.readFileSync(path.join(indicoBaseDir, '.eslintrc.yml'))); + currentMap = defaultConfig.settings['import/resolver'].alias.map; +} catch (e) { + console.error(e); +} + +const reactPath = resolve.sync('react', {basedir: indicoBaseDir}); +const react = require(reactPath); + +module.exports = _.merge(defaultConfig, { + settings: { + 'react': { + version: react.version, + }, + 'import/resolver': { + alias: { + map: currentMap.map(([k, v]) => [k, path.resolve(indicoBaseDir, v)]), + }, + node: { + paths: path.join(indicoBaseDir, 'node_modules'), + }, + }, + }, +}); diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..604a288 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +"eslint-config-indico/prettier-config" diff --git a/package.json b/package.json new file mode 100644 index 0000000..cad7414 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "plugins", + "private": true, + "version": "1.0.0", + "repository": "https://github.com/indico/indico-plugins", + "author": "Indico Team ", + "devDependencies": { + "babel-eslint": "^10.0.2", + "eslint": "^6.0.1", + "eslint-cli": "^1.1.1", + "eslint-config-indico": "^1.2.0", + "eslint-config-prettier": "^6.0.0", + "eslint-import-resolver-alias": "^1.1.2", + "eslint-plugin-babel": "^5.3.0", + "eslint-plugin-import": "^2.18.0", + "eslint-plugin-prettier": "^3.1.0", + "eslint-plugin-react": "^7.14.2", + "eslint-plugin-react-hooks": "^1.6.1", + "lodash": "^4.17.14", + "prettier": "^1.18.2" + } +}