Skip to content

Commit

Permalink
Make big sweeping major breaking changes
Browse files Browse the repository at this point in the history
After lots of usage, I have some insights about the problem space that
make me realize that the current implementation leaves some to be
desired. While the ESLint and Prettier combo are great, it's hard to
apply CSpell or TypeScript to the majority of 'normal' codebases. The
CSpell dictionary is tiny, and TypeScript doesn't understand that these
two things are the same:

```javascript
// Completely understood by TypeScript.
typeof s === 'string

// Completely opaque to TypeScript.
((x) => typeof x === 'string')(x)
```

The JavaScript codebases that I've been working with make heavy use of
utilities like `isString()`, which means that TypeScript reports an
unfortunate number of false positives that would require removing lots
of utility classes. For these reasons, this commit removes CSpell and
TypeScript.

This commit also removes Dependency-Check: it's a wonderful project, and
I still think this is critical, but it's minimalist aesthetic means that
we've had to add lots of `--ignore` garbage to `npm test`. There's a
similar project, Depcheck, which seems to be a less-minimalist approach
to the problem. My experience so far has been positive, and I'm
interested in continuing my experience with Depcheck.

This also introduces a `common-good both` command, which runs `fix` and
then `check`, and brings a Markdown plugin to ESLint so that our readmes
can get linted too! I'm interested in adding a TypeScript plugin as
well, but I'm losing steam for the day and want to push what I've got.
  • Loading branch information
christianbundy committed Sep 10, 2020
1 parent dd7260b commit 3dc492e
Show file tree
Hide file tree
Showing 5 changed files with 1,196 additions and 1,370 deletions.
11 changes: 4 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
es2021: true,
node: true,
},
extends: "eslint:recommended",
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
},
extends: ["eslint:recommended"],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 12,
},
plugins: ["markdown"],
rules: {},
};
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ so that you don't have to install or configure them on your own. Each tool works
automatically without any configuration, which reduces the number of problems
your project needs to manage.

- **[CSpell][0]:** All of your code should use real English words, when possible.
- **[Dependency-Check][1]:** The dependencies you use should match `package.json`.
- **[ESLint][2]:** Your JavaScript should avoid common problems.
- **[Prettier][3]:** All of your code should be formatted predictably.
- **[StyleLint][4]:** Your styles (CSS, SCSS, etc) should avoid common problems.
- **[TypeScript][5]:** Your JavaScript should pass basic type analysis.
- **[Depcheck][1]** -- The dependencies you use should match `package.json`.
- **[ESLint][2]** -- Your JavaScript should avoid common problems.
- **[Prettier][3]** -- All of your code should be formatted predictably.
- **[StyleLint][4]** -- Your styles (CSS, SCSS, etc) should avoid common problems.

## Usage

Install with [npm](https://npmjs.org/):

```javascript
```sh
npm install --save-dev common-good
```

Expand All @@ -27,7 +25,8 @@ Add common-good to `package.json`:
{
"scripts": {
"fix": "common-good fix",
"test": "common-good check"
"test": "common-good test"
}
}
```

Expand All @@ -37,9 +36,7 @@ Resolve small problems with `npm run fix` and test code with `npm test`.

AGPL-3.0

[0]: https://github.com/streetsidesoftware/cspell#readme
[1]: https://github.com/dependency-check-team/dependency-check
[1]: https://github.com/depcheck/depcheck
[2]: https://eslint.org/
[3]: https://prettier.io/
[4]: https://stylelint.io/
[5]: https://www.typescriptlang.org/
33 changes: 20 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,25 @@ if (main === "") {

const eslintConfig = require.resolve("./.eslintrc");

const checkCommands = [
`eslint -c ${eslintConfig} **/*.{js,ts}`,
const testCommands = [
`eslint -c ${eslintConfig} **/*.{js,md,ts}`,
"stylelint --allow-empty-input **/*.css",
`tsc --allowJs --resolveJsonModule --lib es2018,dom --checkJs --noEmit --skipLibCheck ${main}`,
"dependency-check --missing -i common-good ./package.json",
"cspell --no-summary **/*.{js,ts,md}",
"prettier --check .",
"depcheck",
];

const fixCommands = [
"prettier --write .",
"stylelint --fix --allow-empty-input **/*.css",
`eslint -c ${eslintConfig} --fix **/*.{js,ts}`,
`eslint -c ${eslintConfig} --fix **/*.{js,md,ts}`,
];

const run = (command) => {
const moduleName = command.split(" ")[0];
const restOfCommand = command.split(" ").slice(1);

const suffixIndex = process.argv.findIndex(
(arg) => arg === `--${moduleName}-suffix`
(arg) => arg === `--${moduleName}`
);

if (suffixIndex !== -1) {
Expand All @@ -63,15 +61,24 @@ const run = (command) => {
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
process.exit(1);
}
return result.status;
};

const subCommand = process.argv[2];

if (subCommand == null || subCommand === "check") {
checkCommands.forEach(run);
const runAll = (commands) => {
if (!commands.map(run).every((status) => status === 0)) {
process.exit(1);
}
};

if (subCommand === "test") {
runAll(testCommands);
} else if (subCommand === "fix") {
fixCommands.forEach(run);
runAll(fixCommands);
} else if (subCommand === "both") {
runAll(fixCommands);
runAll(testCommands);
} else {
console.log("Usage: common-good <test|fix|both>");
}
Loading

0 comments on commit 3dc492e

Please sign in to comment.