Skip to content

Commit

Permalink
feat: rewrite @hela/eslint from scratch (#222)
Browse files Browse the repository at this point in the history
plus upgrade deps and add publishConfig.registry to other packages
  • Loading branch information
Charlike Mike Reagent authored Mar 6, 2020
1 parent 96c1f7c commit a0d43d4
Show file tree
Hide file tree
Showing 29 changed files with 770 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ dist

!*.*js
!*.*ts

memoize-fs.js
# globbing.js
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

module.exports = {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2020,
},
extends: [
'@tunnckocore/eslint-config',
'@tunnckocore/eslint-config/mdx',
Expand All @@ -9,4 +13,7 @@ module.exports = {
'@tunnckocore/eslint-config/promise',
'@tunnckocore/eslint-config/unicorn',
],
rules: {
'import/no-unresolved': 'off',
},
};
6 changes: 4 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ jobs:
- name: Installing dependencies
if: steps.nodejs-cache.outputs.cache-hit != 'true'
run: yarn run setup:ci
- name: Linting & Format codebase with ESLint and Prettier
run: yarn run lint && yarn run format
- name: Linting & Format with Hela ESLint
run: yarn run lint
- name: Format full codebase with Prettier
run: yarn run format
test:
if: "!contains(toJson(github.event.commits), '[skip ci]')"
env:
Expand Down
6 changes: 6 additions & 0 deletions .hela.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const helaDev = require('@hela/dev');

Object.assign(exports, helaDev);
exports.eslint = require('@hela/eslint').helaCommand();
1 change: 1 addition & 0 deletions .lint.config.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ coverage
*.jpeg
*.jpg
.now
.lint.config.js

# !*.*js*
# !*.*ts*
Expand Down
1 change: 1 addition & 0 deletions commands/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/commit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions commands/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
5 changes: 0 additions & 5 deletions hela.js

This file was deleted.

1 change: 1 addition & 0 deletions modules/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
26 changes: 25 additions & 1 deletion modules/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ prog

module.exports = async function main() {
const cfgPath = argv.c || argv.config;
const cfg = cfgPath ? await explorer.load(cfgPath) : await explorer.search();
const cfg = await tryLoadConfig(cfgPath);

if (!isValidConfig(cfg)) {
throw new HelaError('No config found or invalid. Try "--config" flag.');
Expand Down Expand Up @@ -91,3 +91,27 @@ function isValidConfig(val) {
function isObject(val) {
return val && typeof val === 'object' && Array.isArray(val) === false;
}

async function tryLoadConfig(name) {
let mod = null;

try {
mod = require(name);
if (mod) {
mod = { config: mod, filepath: name };
}
} catch (err) {
if (name) {
try {
mod = await explorer.load(name);
} catch (e) {
try {
mod = await explorer.search();
} catch (_) {
mod = null;
}
}
}
}
return mod || explorer.search();
}
1 change: 1 addition & 0 deletions modules/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
1 change: 1 addition & 0 deletions modules/yaro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
Expand Down
28 changes: 23 additions & 5 deletions modules/yaro/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class Yaro {
this.option('-v, --version', 'Display version');
}

// NOTE: use only when single command mode to define like `my-cmd [...files]`
// it is later use in `.command` (which in the case of singleMode is called from `.action`)
// instead of the `rawName`.
usage(str) {
// for now only in single command mode
if (this.settings.singleMode) {
this._usg = str ? str.trim() : '';
}

return this;
}

command(rawName, description, config) {
if (this.settings.singleMode === true && !config.singleMode) {
throw new Error('in single mode cannot add commands');
Expand Down Expand Up @@ -124,7 +136,9 @@ class Yaro {
const fn = (...args) => handler.apply(this, args);

if (!this.currentCommand && this.settings.singleMode === true) {
this.command('$$root', 'On single mode', { singleMode: true });
const cmd = this._usg ? ` ${this._usg}` : '';

this.command(`$$root${cmd}`, 'On single mode', { singleMode: true });
}
this.currentCommand.handler = fn;
this.__updateCommandsList();
Expand Down Expand Up @@ -208,10 +222,11 @@ class Yaro {
// it's general help, so include commands
if (!commandName) {
const cmdStr = this.settings.defaultCommand ? ' [command]' : ' <command>';
const usg = this.settings.singleMode ? `${this._usg} ` : '';
sections.push({
title: 'Usage',
body: ` $ ${this.programName}${commands.length > 0 ? cmdStr : ''} ${
this.flags.size > 0 ? '[options]' : ''
this.flags.size > 0 ? `${usg}[options]` : ''
}`,
});

Expand Down Expand Up @@ -536,13 +551,16 @@ class Yaro {
});

const parsedArgv = { ...parsed };
const rawArgs = parsed._;
const rawArgs = parsed._.slice();
delete parsed._;

const flags = { ...parsed };

const cmdName = rawArgs.slice(0, 1)[0];
const args = rawArgs.slice(1);
const cmdName = this.settings.singleMode
? '$$root'
: rawArgs.slice(0, 1)[0];

const args = this.settings.singleMode ? rawArgs : rawArgs.slice(1);
const idx = args.findIndex((x) => x === '--');
const argsBefore = args.slice(0, idx - 1);
const argsAfter = args.slice(idx - 1);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"bootstrap": "lerna bootstrap --since",
"clean:fresh": "lerna clean -y && rm -rf node_modules yarn.lock",
"format": "prettier '**/*.{js,md,json}' --write",
"lint": "eslint '{commands,modules,packages,presets}/*/{src,__tests__}/**/*.js' --fix --cache --quiet --format codeframe",
"lint": "hela eslint --fix",
"lint:fresh": "rm -rf .cache/hela-eslint-cache && hela eslint --fix",
"release": "lerna version && lerna publish from-package",
"presetup": "echo foo-bar",
"setup": "yarn",
Expand All @@ -22,11 +23,12 @@
"setup:full": "yarn audit && yarn run setup:locklint && yarn run bootstrap",
"setup:locklint": "lockfile-lint --path yarn.lock --type yarn --validate-https",
"test": "jest",
"test:ci": "jest --coverage"
"test:ci": "jest --coverage --onlyChanged"
},
"dependencies": {
"@tunnckocore/eslint-config": "^5.4.5",
"@tunnckocore/prettier-config": "^1.3.4",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"husky": "^4.2.3",
"jest": "^25.1.0",
Expand All @@ -35,12 +37,10 @@
"prettier": "^1.19.1",
"prettier-plugin-pkgjson": "^0.2.4"
},
"hela": "./.hela.config.js",
"renovate": {
"extends": [
"@tunnckocore"
]
},
"hela": {
"extends": "@hela/dev"
}
}
1 change: 1 addition & 0 deletions packages/eslint/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const mod = require('../src/index');

test('todo test for mod', () => {
// const foo = 123;x
expect(typeof mod).toStrictEqual('object');
expect(typeof mod.helaCommand).toStrictEqual('function');
});
15 changes: 9 additions & 6 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@
"node": ">= 10.13"
},
"publishConfig": {
"registry": "https://registry.npmjs.com",
"access": "public",
"tag": "latest"
},
"scripts": {},
"dependencies": {
"@hela/core": "^3.1.0",
"eslint": "^6.8.0",
"find-pkg": "^2.0.0",
"glob-cache": "^1.0.1",
"memoize-fs": "^2.1.0"
},
"keywords": [
"tunnckocorehq",
"tunnckocore-oss",
"hela",
"development",
"developer-experience",
"dx"
],
"dependencies": {
"@hela/core": "^3.1.0",
"eslint": "^6.8.0",
"glob-cache": "^0.3.5"
}
]
}
Loading

0 comments on commit a0d43d4

Please sign in to comment.