Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of Life Improvements for Development #1043

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

blackxored
Copy link
Contributor

@blackxored blackxored commented Nov 21, 2018

This PR is an initial step towards providing general improvements for developers and contributors of SLOBS.

  • Ensure consistency between settings (match Prettier config with TSLint rule for example).
  • Gets ESLint working.
  • Adds EditorConfig so editors can easily pickup our settings, and aid in cross-platform development (e.g. line feeds).
  • Upgrades TypeScript to latest (3.1.6 3.2.1). Updating selection API (which was apparently outdated) and pinning @types/jquery (used from our deps) were the only required changes.
  • The more important parts are opt-in validations and automation. Details follow.
  • Since rimraf was already a dependency, I don't believe there's a need to use shx anymore (we're only using it to rm -rf files). In addition, there's less typing and more clarify in our scripts section of our package.json. And yes, I've looked at Use cross-platform commands #693 😂. Still unclear to me why rimraf is on dependencies instead of devDependencies BTW.
  • Specify minimum node version, and prevent running on future versions. See commit message for details.

Opt-in

The following is opt-in behavior, meaning it's not enabled by default, as to not hinder the team and new contributors. However, I'd strongly recommend everyone to do opt in.

Here's how:

Create a file called .opt-in at the root of the repository, with the options you wish to enable (one per line).

  • pre-commit:

    • Source code files are formatted with Prettier automatically.
    • Source code files are checked with TSLint and ESLint automatically.
  • commit-msg:

    • Commit messages are validated to follow a convention.
      See Conventional Commits and commitlint-config-conventional for details. The benefits of a commit convention include, but not limited to, consistency in commit types (with the side-effect of shorted and more focused commits, e.g fixes vs features), automatic changelog generation, semantic versioning once we reach 1.0, etc).

Please note, if you do opt-in, that since these are new practices, not enforced before, there's a good chance you might want a workaround if something gets in your way coming from unrelated areas.
While we encourage you to fix as many as you can, you can always opt-out in an case by case basis by running git commit -n.

Documenting this in something like a CONTRIBUTING.md is perhaps something we'd like to do at some point in the future, for visibility.

"singleQuote": true,
"printWidth": 100,
"endOfLine": "lf",
"trailingComma": "all"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yas trailing commas 👍

@blackxored
Copy link
Contributor Author

Sneak peak: PR feedback (coming up later, not for now)

Warnings

❗ Big PR (1)

Markdowns

(1) : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.

New dependencies added: @commitlint/cli, @commitlint/config-conventional, @commitlint/prompt, @commitlint/prompt-cli, commitizen, cross-spawn, eslint-config-prettier, eslint-import-resolver-webpack, husky, lint-staged, prettier, read-pkg-up and which.

@commitlint/cli

Author: Mario Nebl

Description: Lint your commit messages

Homepage: https://github.com/marionebl/commitlint#readme

Createdover 1 year ago
Last Updated15 days ago
LicenseMIT
Maintainers3
Releases43
Direct Dependencies@commitlint/format, @commitlint/lint, @commitlint/load, @commitlint/read, babel-polyfill, chalk, get-stdin, lodash.merge, lodash.pick, meow, resolve-from and resolve-global
Keywordsconventional-changelog, commitlint and cli
README

Lint commit messages

@commitlint/cli

Getting started

npm install --save-dev @commitlint/cli @commitlint/config-angular
echo "module.exports = {extends: ['@commitlint/config-angular']};" > commitlint.config.js

Consult docs/cli for comprehensive documentation.

@commitlint/config-conventional

Author: Mario Nebl

Description: Shareable commitlint config enforcing conventional commits

Homepage: https://github.com/marionebl/commitlint#readme

Created12 months ago
Last Updated15 days ago
LicenseMIT
Maintainers3
Releases16
Keywordsconventional-changelog, commitlint, commitlint-config and angular
README

Lint your conventional commits

@commitlint/config-conventional

Shareable commitlint config enforcing conventional commits.
Use with @commitlint/cli and @commitlint/prompt-cli.

⚠️
IMPORTANT This is a direct replacement for @commitlint/config-angular prior to version 4. config-angular diverged from the conventional commit convention as of version 5. See #146 for details.

Getting started

npm install --save-dev @commitlint/config-conventional @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

Rules

Problems

The following rules are considered problems for @commitlint/config-conventional and will yield a non-zero exit code when not met.

Consult docs/rules for a list of available rules.

type-enum

  • condition: type is found in value

  • rule: always

  • value

    [
      'build',
      'ci',
      'chore',
      'docs',
      'feat',
      'fix',
      'perf',
      'refactor',
      'revert',
      'style',
      'test'
    ]
echo "foo: some message" # fails
echo "fix: some message" # passes

type-case

  • description: type is in case value
  • rule: always
  • value
      'lowerCase'
echo "FIX: some message" # fails
echo "fix: some message" # passes

type-empty

  • condition: type is empty
  • rule: never
echo ": some message" # fails
echo "fix: some message" # passes

scope-case

  • condition: scope is in case value
  • rule: always
  'lowerCase'
echo "fix(SCOPE): some message" # fails
echo "fix(scope): some message" # passes

subject-case

  • condition: subject is in one of the cases ['sentence-case', 'start-case', 'pascal-case', 'upper-case']
  • rule: never
echo "fix(SCOPE): Some message" # fails
echo "fix(SCOPE): Some Message" # fails
echo "fix(SCOPE): SomeMessage" # fails
echo "fix(SCOPE): SOMEMESSAGE" # fails
echo "fix(scope): some message" # passes
echo "fix(scope): some Message" # passes

subject-empty

  • condition: subject is empty
  • rule: never
echo "fix:" # fails
echo "fix: some message" # passes

subject-full-stop

  • condition: subject ends with value
  • rule: never
  • value
  '.'
echo "fix: some message." # fails
echo "fix: some message" # passes

header-max-length

  • condition: header has value or less characters
  • rule: always
  • value
  72
echo "fix: some message that is way too long and breaks the line max-length by several characters" # fails
echo "fix: some message" # passes

@commitlint/prompt

Author: Mario Nebl

Description: commitizen prompt using commitlint.config.js

Homepage: https://github.com/marionebl/commitlint#readme

Createdover 1 year ago
Last Updated15 days ago
LicenseMIT
Maintainers3
Releases41
Direct Dependencies@commitlint/load, babel-runtime, chalk, lodash.camelcase, lodash.kebabcase, lodash.snakecase, lodash.startcase, lodash.topairs, lodash.upperfirst, throat and vorpal
Keywordsconventional-changelog, commitlint, prompt, cz and commitizen
README

commitizen adapter using commitlint.config.js

@commitlint/prompt

This is the library and commitizen adapter version of commitlint prompt.
A ready-to-use cli version is available at @commitlint/prompt-cli.
Learn how to use it at docs/prompt.

Getting started

npm install --save-dev @commitlint/prompt @commitlint/config-angular commitizen
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

In package.json

{
  "scripts": {
    "commit": "git-cz"
  },
  "config": {
    "commitizen": {
      "path": "@commitlint/prompt"
    }
  }
}
git add .
npm run commit

@commitlint/prompt-cli

Author: Mario Nebl

Description: commit prompt using commitlint.config.js

Homepage: https://github.com/marionebl/commitlint#readme

Createdover 1 year ago
Last Updated15 days ago
LicenseMIT
Maintainers3
Releases41
Direct Dependencies@commitlint/prompt, execa and meow
Keywordscommitlint and prompt
README

commit prompt using commitlint.config.js

@commitlint/prompt-cli

Getting started

npm install --g @commitlint/prompt-cli @commitlint/config-angular
echo "module.exports = {extends: ['@commitlint/config-angular']};" > commitlint.config.js
git add .
commit

A full usage guide is available at docs/prompt.

commitizen

Author: Jim Cummins

Description: Git commit, but play nice with conventions.

Homepage: https://github.com/commitizen/cz-cli

Createdover 3 years ago
Last Updated17 days ago
LicenseMIT
Maintainers5
Releases54
Direct Dependenciescachedir, cz-conventional-changelog, dedent, detect-indent, find-node-modules, find-root, fs-extra, glob, inquirer, lodash, minimist, shelljs and strip-json-comments
Keywordscommit, pretty, format, conventional changelog and commitizen
This README is too long to show.

cross-spawn

Author: André Cruz

Description: Cross platform child_process#spawn and child_process#spawnSync

Homepage: https://github.com/moxystudio/node-cross-spawn

Createdover 4 years ago
Last Updated7 months ago
LicenseMIT
Maintainers1
Releases50
Direct Dependenciesnice-try, path-key, semver, shebang-command and which
Keywordsspawn, spawnSync, windows, cross-platform, path-ext, shebang, cmd and execute
README

cross-spawn

NPM version Downloads Build Status Build status Coverage Status Dependency status Dev Dependency status Greenkeeper badge

A cross platform solution to node's spawn and spawnSync.

Installation

$ npm install cross-spawn

Why

Node has issues when using spawn on Windows:

  • It ignores PATHEXT
  • It does not support shebangs
  • Has problems running commands with spaces
  • Has problems running commands with posix relative paths (e.g.: ./my-folder/my-executable)
  • Has an issue with command shims (files in node_modules/.bin/), where arguments with quotes and parenthesis would result in invalid syntax error
  • No options.shell support on node <v4.8

All these issues are handled correctly by cross-spawn.
There are some known modules, such as win-spawn, that try to solve this but they are either broken or provide faulty escaping of shell arguments.

Usage

Exactly the same way as node's spawn or spawnSync, so it's a drop in replacement.

const spawn = require('cross-spawn');

// Spawn NPM asynchronously
const child = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });

// Spawn NPM synchronously
const result = spawn.sync('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });

Caveats

Using options.shell as an alternative to cross-spawn

Starting from node v4.8, spawn has a shell option that allows you run commands from within a shell. This new option solves
the PATHEXT issue but:

  • It's not supported in node <v4.8
  • You must manually escape the command and arguments which is very error prone, specially when passing user input
  • There are a lot of other unresolved issues from the Why section that you must take into account

If you are using the shell option to spawn a command in a cross platform way, consider using cross-spawn instead. You have been warned.

options.shell support

While cross-spawn adds support for options.shell in node <v4.8, all of its enhancements are disabled.

This mimics the Node.js behavior. More specifically, the command and its arguments will not be automatically escaped nor shebang support will be offered. This is by design because if you are using options.shell you are probably targeting a specific platform anyway and you don't want things to get into your way.

Shebangs support

While cross-spawn handles shebangs on Windows, its support is limited. More specifically, it just supports #!/usr/bin/env <program> where <program> must not contain any arguments.
If you would like to have the shebang support improved, feel free to contribute via a pull-request.

Remember to always test your code on Windows!

Tests

$ npm test
$ npm test -- --watch during development

License

Released under the MIT License.

eslint-config-prettier

Author: Simon Lydell

Description: Turns off all rules that are unnecessary or might conflict with Prettier.

Homepage: https://github.com/prettier/eslint-config-prettier#readme

Createdalmost 2 years ago
Last Updated11 days ago
LicenseMIT
Maintainers1
Releases30
Direct Dependenciesget-stdin
Keywordseslint, eslintconfig and prettier
This README is too long to show.

eslint-import-resolver-webpack

Author: Ben Mosher

Description: Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.

Homepage: https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/webpack

Createdalmost 3 years ago
Last Updated5 months ago
LicenseMIT
Maintainers3
Releases29
Direct Dependenciesarray-find, debug, enhanced-resolve, find-root, has, interpret, lodash, node-libs-browser, resolve and semver
Keywordseslint-plugin-import, eslint, jsnext, modules and webpack
README

eslint-import-resolver-webpack

npm

Webpack-literate module resolution plugin for eslint-plugin-import.

Published separately to allow pegging to a specific version in case of breaking
changes.

To use with eslint-plugin-import, run:

npm i eslint-import-resolver-webpack -g

or if you manage ESLint as a dev dependency:

# inside your project's working tree
npm install eslint-import-resolver-webpack --save-dev

Will look for webpack.config.js as a sibling of the first ancestral package.json,
or a config parameter may be provided with another filename/path either relative to the
package.json, or a complete, absolute path.

If multiple webpack configurations are found the first configuration containing a resolve section will be used. Optionally, the config-index (zero-based) setting can be used to select a specific configuration.

---
settings:
  import/resolver: webpack  # take all defaults

or with explicit config file name:

---
settings:
  import/resolver:
    webpack:
      config: 'webpack.dev.config.js'

or with explicit config file name:

---
settings:
  import/resolver:
    webpack:
      config: 'webpack.multiple.config.js'
      config-index: 1   # take the config at index 1

or with explicit config object:

---
settings:
  import/resolver:
    webpack:
      config:
        resolve:
          extensions:
            - .js
            - .jsx

husky

Author: Typicode

Description: Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)

Homepage: https://github.com/typicode/husky#readme

Createdover 4 years ago
Last Updated2 days ago
LicenseMIT
Maintainers1
Releases106
Direct Dependenciescosmiconfig, execa, find-up, get-stdin, is-ci, pkg-dir, please-upgrade-node, read-pkg, run-node and slash
Keywordsgit, hook, hooks, pre-commit, precommit, post-commit, postcommit, pre-push, prepush, post-merge, postmerge, test and lint
README

husky

Git hooks made easy

Mac/Linux Build Status Windows Build status

Husky can prevent bad git commit, git push and more 🐶 woof!

Support

Do you ❤️ husky? You can support its development on Patreon!

Install

npm install husky --save-dev
// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "npm test",
      "pre-push": "npm test",
      "...": "..."
    }
  }
}
git commit -m 'Keep calm and commit'

To go further, see the docs here.

Uninstall

npm uninstall husky

Upgrading from 0.14

Simply move your existing hooks to husky.hooks field and use raw Git hooks names. Also, if you're using the GIT_PARAMS env variable, rename it to HUSKY_GIT_PARAMS.

{
  "scripts": {
-   "precommit": "npm test",
-   "commitmsg": "commitlint -E GIT_PARAMS"
  },
+ "husky": {
+   "hooks": {
+     "pre-commit": "npm test",
+     "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
+   }
+ }
}

Alternatively, you can run the following command which will do the same automatically for you ;)

./node_modules/.bin/husky-upgrade

Starting with 1.0.0, you can also configure hooks using .huskyrc, .huskyrc.json or .huskyrc.js file.

// .huskyrc
{
  "hooks": {
    "pre-commit": "npm test"
  }
}

To view the full list of changes, please see the CHANGELOG.

Features

  • Keeps existing user hooks
  • Supports GUI Git clients
  • Supports all Git hooks (pre-commit, pre-push, ...)

Used by

See also

  • pkg-ok - Prevents publishing a module with bad paths or incorrect line endings
  • please-upgrade-node - Show a message to upgrade Node instead of a stacktrace in your CLIs
  • pinst - dev only postinstall hook

License

MIT

Patreon - Supporters

lint-staged

Author: Andrey Okonetchnikov

Description: Lint files staged by git

Homepage: https://github.com/okonet/lint-staged#readme

Createdalmost 3 years ago
Last Updated1 day ago
LicenseMIT
Maintainers1
Releases87
Direct Dependencies@iamstarkov/listr-update-renderer, chalk, commander, cosmiconfig, debug, dedent, del, execa, find-parent-dir, g-status, is-glob, is-windows, jest-validate, listr, lodash, log-symbols, micromatch, npm-which, p-map, path-is-inside, pify, please-upgrade-node, staged-git-files, string-argv and stringify-object
Keywordslint, git, staged, eslint, prettier, stylelint, code, quality, check, format and validate
This README is too long to show.

prettier

Author: James Long

Description: Prettier is an opinionated code formatter

Homepage: https://prettier.io

Createdalmost 2 years ago
Last Updated12 days ago
LicenseMIT
Maintainers6
Releases79
README

Prettier Banner

Opinionated Code Formatter

JavaScript · TypeScript · Flow · JSX · JSON
CSS · SCSS · Less
HTML · Vue · Angular
GraphQL · Markdown · YAML
Your favorite language?

Travis CI Build Status CircleCI Build Status AppVeyor Build Status Codecov Coverage Status Blazing Fast
npm version weekly downloads from npm code style: prettier Chat on Gitter Follow Prettier on Twitter

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

Input

foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());

Output

foo(
  reallyLongArg(),
  omgSoManyParameters(),
  IShouldRefactorThis(),
  isThereSeriouslyAnotherOne()
);

Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!


Documentation

Install ·
Options ·
CLI ·
API

Playground


Badge

Show the world you're using Prettiercode style: prettier

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

Contributing

See CONTRIBUTING.md.

read-pkg-up

Author: Sindre Sorhus

Description: Read the closest package.json file

Homepage: https://github.com/sindresorhus/read-pkg-up#readme

Createdabout 3 years ago
Last Updated5 months ago
LicenseMIT
Maintainers1
Releases4
Direct Dependenciesfind-up and read-pkg
Keywordsjson, read, parse, file, fs, graceful, load, pkg, package, find, up, find-up, findup, look-up, look, search, match, resolve, parent, parents, folder, directory, dir, walk, walking and path
README

read-pkg-up Build Status

Read the closest package.json file

Why

Install

$ npm install read-pkg-up

Usage

const readPkgUp = require('read-pkg-up');

(async () => {
	console.log(await readPkgUp());
	/*
	{
		pkg: {
			name: 'awesome-package',
			version: '1.0.0',

		},
		path: '/Users/sindresorhus/dev/awesome-package/package.json'
	}
	*/
})();

API

readPkgUp([options])

Returns a Promise for the result object.

readPkgUp.sync([options])

Returns the result object.

options

Type: Object

cwd

Type: string

Default: process.cwd()

Directory to start looking for a package.json file.

normalize

Type: boolean

Default: true

Normalize the package data.

Related

  • read-pkg - Read a package.json file
  • pkg-up - Find the closest package.json file
  • find-up - Find a file by walking up parent directories
  • pkg-conf - Get namespaced config from the closest package.json

License

MIT © Sindre Sorhus

which

Author: Isaac Z. Schlueter

Description: Like which(1) unix command. Find the first instance of an executable in the PATH.

Homepage: https://github.com/isaacs/node-which#readme

Createdover 7 years ago
Last Updated5 months ago
LicenseISC
Maintainers1
Releases27
Direct Dependenciesisexe
README

which

Like the unix which utility.

Finds the first instance of a specified executable in the PATH
environment variable. Does not cache the results, so hash -r is not
needed when the PATH changes.

USAGE

var which = require('which')

// async usage
which('node', function (er, resolvedPath) {
  // er is returned if no "node" is found on the PATH
  // if it is found, then the absolute path to the exec is returned
})

// sync usage
// throws if not found
var resolved = which.sync('node')

// if nothrow option is used, returns null if not found
resolved = which.sync('node', {nothrow: true})

// Pass options to override the PATH and PATHEXT environment vars.
which('node', { path: someOtherPath }, function (er, resolved) {
  if (er)
    throw er
  console.log('found at %j', resolved)
})

CLI USAGE

Same as the BSD which(1) binary.

usage: which [-as] program ...

OPTIONS

You may pass an options object as the second argument.

  • path: Use instead of the PATH environment variable.
  • pathExt: Use instead of the PATHEXT environment variable.
  • all: Return all matches, instead of just the first one. Note that
    this means the function returns an array of strings instead of a
    single string.

Danger: ✓ found only warnings, not failing the build

@AppVeyorBot
Copy link

❌ build failed

@blackxored blackxored force-pushed the chore/quality-of-life branch 4 times, most recently from 2c0bd07 to 7e9c67e Compare November 29, 2018 21:08
@blackxored blackxored changed the base branch from staging to staging2 November 29, 2018 21:21
@blackxored blackxored force-pushed the chore/quality-of-life branch 2 times, most recently from 144e2c8 to 7744923 Compare December 10, 2018 23:43
@blackxored blackxored changed the base branch from staging2 to staging December 10, 2018 23:49
@blackxored blackxored force-pushed the chore/quality-of-life branch from 7744923 to 6014187 Compare December 11, 2018 19:46
* add opt-in quality of life improvements for development, details
follow.
* add `.editorconfig`.
* move prettier config to `package.json`.
* fix precommit script to run on WSL.
* add ignore patterns to unused vars/args
* preliminary work on getting eslint working (though I'm replacing it
with us going full tslint instead).
* replace shx commands with rimraf in `package.json`.
* specify min node and yarn versions.
* Since upgrade to TS was also done on a different branch this specifies
a version range instead.

About improvements:

This is opt-in behavior, meaning it's not enabled by default, as
to not hinder the team and new contributors. However, I strongly
recommend everyone to do opt in.

Here's how:

Create a file called `.opt-in` at the root of the repository,
with the options you wish to enable (one per line).

- `pre-commit`:

  * Source code files are formatted with Prettier automatically.
  * Source code files are checked with TSLint and ESLint automatically.

- `commit-msg`:
  * Commit messages are validated to follow a convention.
  See <https://www.conventionalcommits.org/en/v1.0.0-beta.2/> for
  details.

Please note, if you do opt-in, that since these are new practices, not
enforced before, there's a good chance you might want a workaround if
you're getting warnings from unrelated areas of your current task.
While we encourage you to fix as many as you can, you can always
opt-out in an case by case basis by running `git commit -n`.

About node versions:

Make sure that developers are running a supported and tested version of
Node. When Node 12 comes up, we would explicitly update this field after
testing. This is better than unexpected issues resulting from people
running an early release or a GA release that hasn't been tested.
@blackxored blackxored force-pushed the chore/quality-of-life branch from 6014187 to 465d7d2 Compare December 12, 2018 00:35
@blackxored blackxored merged commit 465d7d2 into staging Dec 12, 2018
@blackxored blackxored deleted the chore/quality-of-life branch December 12, 2018 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants