Skip to content

Commit

Permalink
feat: Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Mar 22, 2021
0 parents commit aa5bad3
Show file tree
Hide file tree
Showing 22 changed files with 9,148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: './index.js',
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json',
},
};
17 changes: 17 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Format"
on:
push:

jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v2
- run: yarn install
- run: yarn run format
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "refactor: Apply eslint fix"
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Release"
on:
push:
branches:
- master

jobs:
# https://docs.github.com/en/actions/guides/publishing-nodejs-packages#publishing-packages-using-yarn
# https://github.com/semantic-release/semantic-release/blob/master/docs/recipes/github-actions.md
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: yarn install
- run: yarn build
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Validate"
on:
pull_request:
push:
branches:
- master

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: yarn install
- run: yarn run lint
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
dist
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@mll-lab/prettier-config');
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 1.0.0 (2021-03-22)


### Bug Fixes

* Clean up CHANGELOG.md, actually release ([ac3b53c](https://github.com/mll-lab/eslint-plugin/commit/ac3b53c735e727797ed7386822519b7b5bd095d4))


### Features

* Initial release ([8b6adc3](https://github.com/mll-lab/eslint-plugin/commit/8b6adc39dc7824139a2659a7911fd2888a34661e))

# 1.0.0 (2021-03-22)


### Features

* Initial release ([7bf7ebd](https://github.com/mll-lab/eslint-plugin/commit/7bf7ebdea801dc88144534b538f39acb2569220c))
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# error vs. warning

Always use `error` for enabled rules, never `warning`.
If the rule is too strict in some cases, violations should be addressed where
they occur instead of spamming the lint output.

# Commit Messages

We use [semantic-release](https://github.com/semantic-release/semantic-release) to automatically generate
- version number
- changelog
- releases

This requires to write commit messages that follow the [Angular commit message format](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format).

Merge requests with a lot of intermediary commits must be cleaned up by force pushing rewritten commits.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 MLL Münchner Leukämielabor GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# eslint-plugin

ESLint plugin and common configuration of MLL

## Installation

yarn add --dev @mll-lab/eslint-plugin

## Configuration

Extend your ESLint configuration file:

```js
"extends": [
"plugin:mll-lab/recommended",
],
```
57 changes: 57 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['airbnb-base', 'plugin:prettier/recommended'],
plugins: ['@typescript-eslint', 'import', 'unused-imports'],
rules: {
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'class', format: ['PascalCase'] },
{ selector: 'enumMember', format: ['UPPER_CASE'] },
],
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
],
'arrow-body-style': ['error', 'as-needed'],
camelcase: 'off',
'class-methods-use-this': 'off',
'comma-dangle': ['error', 'always-multiline'],
'consistent-return': 'off', // Not necessary with TypeScript
'func-names': ['error', 'always'],
'import/extensions': ['error', 'never'],
'import/imports-first': 'error',
'import/newline-after-import': 'error',
'import/no-extraneous-dependencies': 'off',
'import/no-named-as-default': 'error',
'import/no-unresolved': 'off', // We do not use webpack in every project
'import/no-webpack-loader-syntax': 'off',
'import/order': [
'error',
{ 'newlines-between': 'always', alphabetize: { order: 'asc' } },
],
'import/prefer-default-export': 'off',
'max-len': 'off',
'newline-per-chained-call': 'off',
'no-confusing-arrow': 'off',
'no-console': 'error',
'no-nested-ternary': 'error',
'no-param-reassign': ['error', { props: false }],
'no-redeclare': 'off',
'no-shadow': 'off',
'no-underscore-dangle': [
2,
{ allow: ['__typename', '__REDUX_DEVTOOLS_EXTENSION_COMPOSE__'] },
],
'no-unused-vars': 'off', // Replaced by @typescript-eslint/no-unused-vars
'no-use-before-define': 'off',
'object-shorthand': 'error',
'prefer-template': 'error',
'require-yield': 'off',
'unused-imports/no-unused-imports-ts': 'error',
},
};
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
};
71 changes: 71 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@mll-lab/eslint-plugin",
"version": "1.0.0",
"description": "ESLint plugin and common configuration of MLL",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/mll-lab/eslint-plugin.git"
},
"keywords": [
"eslint",
"eslintplugin"
],
"publishConfig": {
"access": "public"
},
"author": "Benedikt Franke <benedikt@franke.tech>",
"license": "MIT",
"bugs": {
"url": "https://github.com/mll-lab/eslint-plugin/issues"
},
"homepage": "https://github.com/mll-lab/eslint-plugin",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-unused-imports": "^1.1.0",
"typescript": "^4.2.3"
},
"peerDependencies": {
"eslint-config-airbnb": "^18.2.1",
"eslint-import-resolver-webpack": "^0.13.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-redux-saga": "^1.2.1",
"eslint-plugin-testing-library": "^3.10.2",
"prettier": "^2.2.1"
},
"scripts": {
"build": "tsc",
"lint": "eslint --ext .js,.ts .",
"format": "yarn run lint --fix",
"test": "jest"
},
"devDependencies": {
"@mll-lab/prettier-config": "^1.0.0",
"@mll-lab/tsconfig": "^1.1.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/jest": "^26.0.21",
"@typescript-eslint/experimental-utils": "^4.18.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-import-resolver-webpack": "^0.13.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-redux-saga": "^1.2.1",
"eslint-plugin-testing-library": "^3.10.2",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"semantic-release": "^17.4.2",
"ts-jest": "^26.5.4"
}
}
10 changes: 10 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/npm',
'@semantic-release/github',
'@semantic-release/changelog',
'@semantic-release/git',
],
};
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { noColorLiterals } from './rules/no-color-literals';

const rules = {
'no-color-literals': noColorLiterals,
};

const recommendedRules = {
'mll-lab/no-color-literals': 'error',
};

export default {
rules,
configs: {
recommended: {
plugins: ['mll-lab'],
rules: recommendedRules,
},
},
};
50 changes: 50 additions & 0 deletions src/rules/no-color-literals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ESLintUtils } from '@typescript-eslint/experimental-utils';

function isColorLiteral(value: unknown): boolean {
if (typeof value !== 'string') {
return false;
}

return Boolean(
value.match(/#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}$)/) ||
value.includes('rgb(') ||
value.includes('rgba('),
);
}

export const noColorLiterals = ESLintUtils.RuleCreator((name) => name)({
name: 'no-color-literals',
meta: {
type: 'problem',
docs: {
description:
'Checks for color strings, such as #000, #000000, rgb(... or rgba(...',
category: 'Best Practices',
recommended: 'error',
},
messages: {
noColorLiterals:
'Do not use absolute color values, import color values from theme.',
},
schema: [],
},
defaultOptions: [],
create: (context) => ({
TemplateElement(node) {
if (isColorLiteral(node.value.raw)) {
context.report({
node,
messageId: 'noColorLiterals',
});
}
},
Literal(node) {
if (isColorLiteral(node.value)) {
context.report({
node,
messageId: 'noColorLiterals',
});
}
},
}),
});
12 changes: 12 additions & 0 deletions tests/rules/no-color-literals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { noColorLiterals } from '../../src/rules/no-color-literals';
import { createRuleTester } from '../test-utils';

createRuleTester().run('no-color-literals', noColorLiterals, {
valid: [],
invalid: [
{
code: 'const color = "#000";',
errors: [{ messageId: 'noColorLiterals' }],
},
],
});
15 changes: 15 additions & 0 deletions tests/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { resolve } from 'path';

import { TSESLint } from '@typescript-eslint/experimental-utils';

export const createRuleTester = (
parserOptions: Partial<TSESLint.ParserOptions> = {},
) =>
new TSESLint.RuleTester({
parser: resolve('./node_modules/@typescript-eslint/parser'),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
...parserOptions,
},
});
4 changes: 4 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["**/*.ts", "**/*.js", ".eslintrc.js"]
}
Loading

0 comments on commit aa5bad3

Please sign in to comment.