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

Typescript, prettier, linting #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
296 changes: 296 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
module.exports = {
root: true,
plugins: [
'jsdoc', //
'promise',
'security',
'import',
'@typescript-eslint',
],
extends: ['eslint:recommended', 'airbnb-base'],
env: {
browser: true,
es6: true,
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
},
},
jsdoc: {
preferredTypes: {
Array: 'Array<object>',
'Array.': 'Array<object>',
'Array<>': '[]',
'Array.<>': '[]',
'Promise.<>': 'Promise<>',
},
},
},
rules: {
'prettier/prettier': [
'error',
{},
{
usePrettierrc: true,
},
],
curly: ['error', 'all'],
'callback-return': ['error', ['callback', 'cb', 'next', 'done']],
'class-methods-use-this': 'off',
'consistent-return': 'off',
'handle-callback-err': ['error', '^.*err'],
'new-cap': 'off',
'no-console': 'error',
'no-else-return': 'error',
'no-eq-null': 'off',
'no-global-assign': 'error',
'no-loop-func': 'off',
'no-lone-blocks': 'error',
'no-negated-condition': 'error',
'no-shadow': 'error',
'no-template-curly-in-string': 'error',
'no-undef': 'error',
'no-underscore-dangle': 'off',
'no-unsafe-negation': 'error',
'no-use-before-define': ['error', 'nofunc'],
'no-useless-rename': 'error',
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: [
'directive', //
'block',
'block-like',
'multiline-block-like',
'cjs-export',
'cjs-import',
'class',
'export',
'import',
'if',
],
next: '*',
},
{ blankLine: 'never', prev: 'directive', next: 'directive' },
{ blankLine: 'any', prev: '*', next: ['if', 'for', 'cjs-import', 'import'] },
{ blankLine: 'any', prev: ['export', 'import'], next: ['export', 'import'] },
{ blankLine: 'always', prev: '*', next: ['try', 'function', 'switch'] },
{ blankLine: 'always', prev: 'if', next: 'if' },
{ blankLine: 'never', prev: ['return', 'throw'], next: '*' },
],
strict: ['error', 'safe'],
'no-new': 'off',
'no-empty': 'error',
'no-empty-function': 'error',
'valid-jsdoc': 'off',
yoda: 'error',

'import/extensions': ['error', 'never'],
'import/no-unresolved': 'off',
'import/order': [
'error',
{
'newlines-between': 'always',
alphabetize: { order: 'asc', caseInsensitive: true },
},
],

'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'off',
'jsdoc/check-param-names': 'off',
'jsdoc/check-tag-names': 'error',
'jsdoc/check-types': 'error',
'jsdoc/newline-after-description': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-description': 'off',
'jsdoc/require-description-complete-sentence': 'off',
'jsdoc/require-example': 'off',
'jsdoc/require-hyphen-before-param-description': 'error',
'jsdoc/require-param': 'error',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-name': 'error',
'jsdoc/require-param-type': 'error',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'error',
'jsdoc/valid-types': 'error',

'promise/always-return': 'error',
'promise/always-catch': 'off',
'promise/catch-or-return': ['error', { allowThen: true }],
'promise/no-native': 'off',
'promise/param-names': 'error',

'security/detect-buffer-noassert': 'error',
'security/detect-child-process': 'error',
'security/detect-disable-mustache-escape': 'error',
'security/detect-eval-with-expression': 'error',
'security/detect-new-buffer': 'error',
'security/detect-no-csrf-before-method-override': 'error',
'security/detect-non-literal-fs-filename': 'error',
'security/detect-non-literal-regexp': 'error',
'security/detect-non-literal-require': 'off',
'security/detect-object-injection': 'off',
'security/detect-possible-timing-attacks': 'error',
'security/detect-pseudoRandomBytes': 'error',
'security/detect-unsafe-regex': 'error',

// Override airbnb
eqeqeq: ['error', 'smart'],
'func-names': 'error',
'id-length': ['error', { exceptions: ['_', '$', 'e', 'i', 'j', 'k', 'q', 'x', 'y'] }],
'no-param-reassign': 'off', // Work toward enforcing this rule
radix: 'off',
'spaced-comment': 'off',
'max-len': 'off',
'no-continue': 'off',
'no-plusplus': 'off',
'no-prototype-builtins': 'off',
'no-restricted-syntax': ['error', 'DebuggerStatement', 'LabeledStatement', 'WithStatement'],
'no-restricted-properties': [
'error',
{
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
},
{
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
},
{
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
},
],
'no-useless-escape': 'off',
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
avoidExplicitReturnArrows: true,
},
],
// 'prefer-arrow-callback': ['error', { 'allowNamedFunctions': true }],
'prefer-spread': 'error',
'prefer-destructuring': 'off',
},
overrides: [
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
},
extends: [
'eslint:recommended',
'airbnb-typescript/base',
'plugin:import/typescript',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
'class-methods-use-this': 'off',
indent: 'off',
'max-classes-per-file': 'off',
'max-len': 'off',
'no-dupe-class-members': 'off',
'no-extra-semi': 'off',
'no-new': 'off',
'no-param-reassign': 'off',
'no-underscore-dangle': 'off',
'no-useless-constructor': 'off',
'no-unused-expressions': 'error',
'no-restricted-syntax': ['error', 'DebuggerStatement', 'LabeledStatement', 'WithStatement'],
'no-use-before-define': 'off',
'no-shadow': 'off',
'no-void': 'off',

'import/prefer-default-export': 'off',
'import/no-cycle': 'off',
'import/no-extraneous-dependencies': 'off',
'import/extensions': ['error', 'never'],
'import/order': [
'error',
{
'newlines-between': 'always',
alphabetize: { order: 'asc', caseInsensitive: true },
},
],

'@typescript-eslint/array-type': ['error', { default: 'array' }],
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-member-accessibility': ['error'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'enumMember',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
},
],
'@typescript-eslint/member-ordering': [
'error',
{
default: [
// Index signature
'signature',
// Fields
'private-field',
'public-field',
'protected-field',
// Constructors
'public-constructor',
'protected-constructor',
'private-constructor',
// Methods
'public-method',
'protected-method',
'private-method',
],
},
],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-semi': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-parameter-properties': ['error', { allows: ['readonly'] }],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-throw-literal': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-regexp-exec': 'warn',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
},
},
],
};
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: jgeurts
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ nbproject
.eslintcache

package-lock.json

index.js
index.js.map
index.d.ts
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname $0)/_/husky.sh"

echo 'NOTE: If node is not found, you may need to run brew link for your specific node version'
/usr/local/bin/node node_modules/.bin/lint-staged
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.git
.gitignore
.editorconfig
.eslintrc.js
.npmrc
.prettierrc.js
.github
.husky

node_modules
npm-debug.log
Expand All @@ -29,3 +32,5 @@ dump.rdb

Dockerfile
Makefile

index.ts
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
save-exact=true
package-lock=false
34 changes: 34 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

module.exports = {
arrowParens: 'always',
bracketSpacing: true,
printWidth: 200,
quoteProps: 'as-needed',
semi: true,
singleQuote: true,
useTabs: false,
tabWidth: 2,
trailingComma: 'all',

overrides: [
{
files: '*.js',
options: {
parser: 'babel',
},
},
{
files: '*.json',
options: {
parser: 'json',
},
},
{
files: '*.ts',
options: {
parser: 'typescript',
},
},
],
};
Loading