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

Use shared eslint config #2564

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
197 changes: 1 addition & 196 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,199 +1,4 @@
/* eslint-env node */
module.exports = {
env: {
browser: true,
es2020: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:prettier/recommended',
'plugin:sonarjs/recommended',
'plugin:jsdoc/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
'prettier',
'sonarjs',
'jsdoc',
'prefer-arrow',
'ban',
],
settings: {
react: {
version: '16.14',
pragma: 'h',
},
},
rules: {
quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'always'],
'prettier/prettier': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^h$' },
],
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple',
},
],
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'no-unused-vars': 'off',
camelcase: 'error',
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
functions: 'never',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
},
],
curly: 'error',
'default-case': 'error',
eqeqeq: ['error', 'always'],
'guard-for-in': 'error',
'id-match': 'error',
'jsdoc/check-indentation': 'error',
'jsdoc/require-jsdoc': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/check-tag-names': 'off',
'max-classes-per-file': ['error', 1],
'multiline-ternary': ['error', 'never'],
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': 'error',
'no-duplicate-imports': 'error',
'no-eval': 'error',
'no-extra-bind': 'error',
'no-magic-numbers': [
'error',
{
ignore: [-1, 0, 1],
ignoreArrayIndexes: true,
},
],
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-return-await': 'error',
'no-sequences': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': [
'error',
{
hoist: 'all',
},
],
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-underscore-dangle': 'error',
'no-var': 'error',
'object-shorthand': ['error', 'never'],
'one-var': ['error', 'never'],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'function' },
{
blankLine: 'always',
prev: 'multiline-block-like',
next: '*',
},
],
'prefer-arrow/prefer-arrow-functions': [
'error',
{
allowStandaloneDeclarations: true,
},
],
'prefer-const': 'error',
'prefer-object-spread': 'error',
radix: 'error',
'spaced-comment': [
'error',
'always',
{
markers: ['/'],
},
],
},
overrides: [
{
files: ['./*.js'],
rules: {
'no-unused-vars': 'error',
'sonarjs/no-duplicate-string': 'off',
},
},
{
files: ['./*.ts'],
rules: {
'sonarjs/no-duplicate-string': 'off',
},
},
{
files: ['src/**/*.{ts,tsx}'],
parser: '@typescript-eslint/parser',
parserOptions: {
parserOption: {
jsx: true,
},
project: 'tsconfig.json',
},
rules: {
'@typescript-eslint/dot-notation': 'error',
},
},
{
files: [
'src/examples/*.{ts,tsx}',
'src/components/**/examples/*.{ts,tsx}',
'src/components/**/examples/**/*.{ts,tsx}',
'src/**/*.spec.{ts,tsx}',
'src/**/*.e2e.{ts,tsx}',
'src/**/*.test-wrapper.{ts,tsx}',
],
parserOptions: {
parserOption: {
jsx: true,
},
project: 'tsconfig.lint.json',
},
rules: {
'@typescript-eslint/dot-notation': 'error',
'sonarjs/no-duplicate-string': 'off',
'sonarjs/no-identical-functions': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-param': 'off',
'no-console': 'off',
'no-magic-numbers': 'off',
'prefer-arrow/prefer-arrow-functions': 'off',
'ban/ban': [
'error',
{
name: ['describe', 'only'],
message: "don't focus tests",
},
{ name: 'fdescribe', message: "don't focus tests" },
{ name: ['it', 'only'], message: "don't focus tests" },
{ name: 'fit', message: "don't focus tests" },
{ name: ['test', 'only'], message: "don't focus tests" },
{ name: 'ftest', message: "don't focus tests" },
],
},
},
],
extends: ['@limetech/eslint-config'],
};
1 change: 1 addition & 0 deletions .prettierrc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this work on Windows (using a symlink that is)? Can you help me out by checking @mjlime?

Just pull this branch down, run npm i and npm run lint. If it doesn't work, you should be getting either an error about there being something wrong with your .prettierrc, or, as I got when I simply removed the symlink, 7,674 lint errors 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tested, and it works when running on Windows in GitHub actions at least 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't look like it works:

...
Oops! Something went wrong! :(

ESLint: 8.52.0

Error: Cannot find package 'node_modules' imported from C:\limecrm\Source\lime-elements\.prettierrc
    at new NodeError (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:18797:5)
    at packageResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19742:9)
    at moduleResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19774:20)
    at defaultResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19879:15)
    at resolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19897:12)
    at importFromFile (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19912:15)
    at loadExternalConfig (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19931:24)
    at Object.transform (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19979:20)
    at run (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/internal/internal.mjs:5757:36)
    at async cacheWrapper (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/internal/internal.mjs:55:22)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm… that's a weird error… it seems the symlink worked, because it complains about not finding modules referenced from the symlinked file.

Which npm version are you running?

Copy link
Contributor

Choose a reason for hiding this comment

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

└$ npm --version
9.8.1
└$ node --version
v18.18.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah crap… I was hoping you were using npm <7, because then the problem would have simply been that peer dependencies didn't get installed automatically.

But since that isn't the case, I don't know what the problem is, and that makes me sad… 😢

I'll look into if we can maybe copy the .prettierrc from @limetech/eslint-config to the consumer package in the postinstall… 🤔

Copy link
Contributor Author

@adrianschmidt adrianschmidt Oct 31, 2023

Choose a reason for hiding this comment

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

@mjlime Ok, now it ought to work. I've put the normal .prettierrc back, and I also put a post-install script in Lundalogik/eslint-config that copies its .prettierrc to the consumer project, but only if there isn't already a .prettierrc file there. So it won't overwrite anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adrianschmidt Still running into problems (npm 9.8.1, node 18.18.2):

$ npm i;npm run lint

up to date, audited 1071 packages in 12s

299 packages are looking for funding
  run `npm fund` for details

8 vulnerabilities (3 moderate, 5 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

> @limetech/[email protected] lint
> npm run lint:src && npm run lint:scss


> @limetech/[email protected] lint:src
> eslint "**/*.{ts,tsx,js}" --max-warnings=0


Oops! Something went wrong! :(

ESLint: 8.52.0

Error: Cannot find package 'node_modules' imported from C:\limecrm\Source\lime-elements\.prettierrc
    at new NodeError (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:18797:5)
    at packageResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19742:9)
    at moduleResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19774:20)
    at defaultResolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19879:15)
    at resolve (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19897:12)
    at importFromFile (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19912:15)
    at loadExternalConfig (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19931:24)
    at Object.transform (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/index.mjs:19979:20)
    at run (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/internal/internal.mjs:5757:36)
    at async cacheWrapper (file:///C:/limecrm/Source/lime-elements/node_modules/prettier/internal/internal.mjs:55:22)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, removing .prettierrc and running it again gave me this:

✖ 46839 problems (46839 errors, 0 warnings)
  46839 errors and 0 warnings potentially fixable with the `--fix` option.

Improvement? You tell me @adrianschmidt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to need to get myself a Windows VM if I'm ever to get this to work, I think… 🤔

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"endOfLine": "auto",
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",
"overrides": [
{
"files": [".prettierrc", "*.json"],
Expand Down
Binary file added kompendium-0.12.5.tgz
Binary file not shown.
Loading