Skip to content

Commit

Permalink
v4: typescript first
Browse files Browse the repository at this point in the history
  • Loading branch information
madimp committed Oct 30, 2024
1 parent ce9e58f commit b07421e
Show file tree
Hide file tree
Showing 125 changed files with 12,864 additions and 10,238 deletions.
205 changes: 200 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,194 @@
module.exports = {
extends: [
'plugin:nop/nop',
'extends': [
'eslint:recommended',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
plugins: [
'jest',
'@typescript-eslint',
],
env: {
jest: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
'no-var': [ 'off' ],

'@typescript-eslint/array-type': [ 'error', {
'default': 'generic',
readonly: 'generic',
} ],
'@typescript-eslint/brace-style': [ 'error', '1tbs' ],
'@typescript-eslint/consistent-type-imports': [ 'error' ],
'@typescript-eslint/explicit-function-return-type': [ 'off' ],
'@typescript-eslint/explicit-module-boundary-types': [ 'off' ],
'@typescript-eslint/indent': [ 'error', 4, {
SwitchCase: 1,
} ],
'@typescript-eslint/member-delimiter-style': [ 'error' ],
'@typescript-eslint/naming-convention': [ 'error',
{
selector: 'default',
format: [ 'camelCase' ],
leadingUnderscore: 'allow',
trailingUnderscore: 'forbid',
filter: {
regex: '^(UNSAFE_componentWillReceiveProps|UNSAFE_componentWillMount|UNSAFE_componentWillUpdate)$',
match: false,
},
},
{
selector: 'class',
format: [ 'PascalCase' ],
},
{
selector: 'enum',
format: [ 'PascalCase', 'UPPER_CASE' ],
},
{
selector: 'enumMember',
format: [ 'camelCase', 'PascalCase', 'UPPER_CASE' ],
},
{
selector: 'function',
format: [ 'camelCase', 'PascalCase' ],
},
{
selector: 'interface',
format: [ 'PascalCase' ],
},
{
selector: 'method',
format: [ 'camelCase', 'snake_case', 'UPPER_CASE' ],
leadingUnderscore: 'allow',
filter: {
regex: '^(UNSAFE_componentWillReceiveProps|UNSAFE_componentWillMount|UNSAFE_componentWillUpdate)$',
match: false,
},
},
{
selector: 'parameter',
format: [ 'camelCase', 'PascalCase' ],
leadingUnderscore: 'allow',
},
{
selector: 'property',
format: null,
},
{
selector: 'typeAlias',
format: [ 'PascalCase' ],
},
{
selector: 'typeParameter',
format: [ 'PascalCase', 'UPPER_CASE' ],
},
{
selector: 'variable',
format: [ 'camelCase', 'PascalCase', 'UPPER_CASE' ],
leadingUnderscore: 'allow',
} ],
'@typescript-eslint/no-duplicate-imports': [ 'error' ],
'@typescript-eslint/no-empty-function': [ 'off' ],
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-useless-constructor': [ 'error' ],
'@typescript-eslint/type-annotation-spacing': 'error',

// отключены в пользу @typescript-eslint
'brace-style': 'off',
camelcase: 'off',
indent: 'off',
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'no-useless-constructor': 'off',

'array-bracket-spacing': [ 'error', 'always' ],
'comma-dangle': [ 'error', 'always-multiline' ],
'comma-spacing': [ 'error' ],
'comma-style': [ 'error', 'last' ],
curly: [ 'error', 'all' ],
'eol-last': 'error',
eqeqeq: [ 'error', 'allow-null' ],
'id-match': [ 'error', '^[\\w$]+$' ],
'jsx-quotes': [ 'error', 'prefer-double' ],
'key-spacing': [ 'error', {
beforeColon: false,
afterColon: true,
} ],
'keyword-spacing': 'error',
'linebreak-style': [ 'error', 'unix' ],
'lines-around-comment': [ 'error', {
beforeBlockComment: true,
allowBlockStart: true,
} ],
'max-len': [ 'error', 160, 4 ],
'no-console': 'error',
'no-empty': [ 'error', { allowEmptyCatch: true } ],
'no-implicit-coercion': [ 'error', {
number: true,
'boolean': true,
string: true,
} ],
'no-mixed-operators': [ 'error', {
groups: [
[ '&&', '||' ],
],
} ],
'no-mixed-spaces-and-tabs': 'error',
'no-multiple-empty-lines': [ 'error', {
max: 2,
maxEOF: 0,
maxBOF: 0,
} ],
'no-multi-spaces': 'error',
'no-multi-str': 'error',
'no-nested-ternary': 'error',
// Это правило добавили в eslint@6 в eslint:recommended. Оно нам не надо
'no-prototype-builtins': 'off',
'no-trailing-spaces': 'error',
'no-spaced-func': 'error',
'no-with': 'error',
'object-curly-spacing': [ 'error', 'always' ],
'object-shorthand': 'off',
'one-var': [ 'error', 'never' ],
'operator-linebreak': [ 'error', 'after' ],
'prefer-const': 'error',
'prefer-rest-params': 'off',
'prefer-spread': 'off',
'quote-props': [ 'error', 'as-needed', {
keywords: true,
numbers: true,
} ],
quotes: [ 'error', 'single', {
allowTemplateLiterals: true,
} ],
radix: 'error',
semi: [ 'error', 'always' ],
'space-before-function-paren': [ 'error', 'never' ],
'space-before-blocks': [ 'error', 'always' ],
'space-in-parens': [ 'error', 'never' ],
'space-infix-ops': 'error',
'space-unary-ops': 'off',
'template-curly-spacing': [ 'error', 'always' ],
'valid-jsdoc': [ 'error', {
requireParamDescription: false,
requireReturnDescription: false,
requireReturn: false,
prefer: {
'return': 'returns',
},
} ],
'wrap-iife': [ 'error', 'inside' ],
yoda: [ 'error', 'never', { exceptRange: true } ],

'jest/consistent-test-it': [ 'error', {
fn: 'it',
withinDescribe: 'it',
Expand All @@ -24,5 +203,21 @@ module.exports = {
'jest/no-large-snapshots': [ 'error', { maxSize: 500 } ],
'jest/valid-expect': 'error',
},
env: {
node: true,
jest: true,
},
overrides: [
{
files: [ '*.ts', '*.tsx' ],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-use-before-define': [ 'error', {
functions: false,
} ],
'prefer-rest-params': 'error',
'prefer-spread': 'error',
},
},
],
};

2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
node-version: 20
- run: npm ci
- run: npm test && npm run ts-compile
- run: npm test && npm run prepack

publish-npm:
needs: build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
tests/server.key
tests/server.crt
coverage
build

38 changes: 19 additions & 19 deletions docs/array_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
из других блоков:

```js
const block_foo = require( '.../blocks/foo' );
const block_bar = require( '.../blocks/bar' );
const blockFoo = require( '.../blocks/foo' );
const blockBar = require( '.../blocks/bar' );
...

const block = de.array( {

block: [
block_foo,
block_bar,
blockFoo,
blockBar,
...
],

} );
```

Когда мы запускаем `de.array`, запускаются все его непосредственные подблоки (`block_foo`, `block_bar`, ...)
Когда мы запускаем `de.array`, запускаются все его непосредственные подблоки (`blockFoo`, `blockBar`, ...)
и из их результатов составляется результат `de.array`'а:

```js
const result = [
// Результат работы block_foo
result_foo,
// Результат работы block_bar
result_bar,
// Результат работы blockFoo
resultFoo,
// Результат работы blockBar
resultBar,
...
];
```
Expand All @@ -43,10 +43,10 @@ const result = [

```js
const result = [
// Ошибка block_foo
error_foo,
// Результат работы block_bar
result_bar,
// Ошибка blockFoo
errorFoo,
// Результат работы blockBar
resultBar,
...
];
```
Expand All @@ -61,12 +61,12 @@ const block = de.array( {

block: [
// Если этот блок зафейлится, то и весь de.array так же зафейлится.
block_foo( {
blockFoo.extend( {
options: {
required: true,
},
} ),
block_bar,
blockBar,
...
],

Expand All @@ -80,10 +80,10 @@ const block = de.array( {
```js
const block = de.array( {
block: [
block_foo,
blockFoo,
de.array( {
block: [
block_quu,
blockQuu,
...
],
} ),
Expand All @@ -96,9 +96,9 @@ const block = de.array( {

```js
const result = [
result_foo,
resultFoo,
[
result_quu,
resultQuu,
...
],
...
Expand Down
2 changes: 1 addition & 1 deletion docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
```js
const cache = {
get: function( { key, context } ) { ... },
set: function( { key, value, maxage, context } ) { ... },
set: function( { key, value, maxage } ) { ... },
};
```

Expand Down
8 changes: 4 additions & 4 deletions docs/cancel.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ const block = de.block( {
```js
options: {
after: ( { result, context } ) => {
if ( result.redirect_url ) {
if ( result.redirectUrl ) {
const { res } = context;

res.statusCode = 302;
res.setHeader( 'location', result.redirect_url );
res.setHeader( 'location', result.redirectUrl );
res.end();
}
},
Expand All @@ -97,13 +97,13 @@ options: {
const block = de.block( {
options: {
after: ( { result, cancel } ) => {
if ( result.redirect_url ) {
if ( result.redirectUrl ) {
// Не делаем редирект изнутри блока,
// но кидаем специальную ошибку о том, что нужно сделать редирект.
//
cancel.cancel( de.error( {
id: 'REDIRECT',
location: result.redirect_url,
location: result.redirectUrl,
status_code: 302,
} ) );
}
Expand Down
4 changes: 2 additions & 2 deletions docs/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const result = de.run( block, { context } );

// Более реалистично
//
const api_config = require( '.../api/config' );
import apiConfig from '.../api/config';

const server = http_.createServer( ( req, res ) => {
const params = ...;
Expand All @@ -65,7 +65,7 @@ const server = http_.createServer( ( req, res ) => {
const context = {
req: req,
res: res,
api: api_config,
api: apiConfig,
};

const result = de.run( block, { params, context } );
Expand Down
Loading

0 comments on commit b07421e

Please sign in to comment.