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

feature/multiple configs #14

Merged
merged 3 commits into from
Jul 25, 2024
Merged
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@ To install the configuration, run the following command:
npm install --save-dev @microsoft/eslint-config-msgraph
```

### eslint configuration

#### non-React projects

If your project does not contain react components, use this configuration.

In your project's eslint config file, add the following entry in your `extends` array:

```js
extends: ['@microsoft/eslint-config-msgraph/core'],
```

#### React projects

If your project contains react components, use this configuration instead.

In your project's eslint config file, add the following entry in your `extends` array:

```js
extends: ['@microsoft/eslint-config-msgraph'],
```

### Prettier configuration

To use the shared Prettier config, add a `prettier.config.cjs` file with the following contents:

```js
Expand Down
89 changes: 89 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: { project: './tsconfig.json' },
plugins: ['eslint-plugin-prefer-arrow', '@typescript-eslint'],
rules: {
'@typescript-eslint/class-literal-property-style': ['error', 'getters'],
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid'
},
{
selector: ['property', 'accessor'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'allow'
},
{
selector: ['variable', 'function'],
format: ['camelCase'],
leadingUnderscore: 'allow'
}
],
'@typescript-eslint/no-shadow': [
'error',
{
hoist: 'all'
}
],
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/restrict-template-expressions': ['error', { allowBoolean: true, allowNumber: true }],
'@typescript-eslint/unified-signatures': 'error',
'dot-notation': 'off',
eqeqeq: ['error', 'smart'],
'guard-for-in': 'error',
'linebreak-style': 'off',
'max-classes-per-file': ['error', 1],
'new-parens': ['error', 'always'],
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-empty-function': 'off',
'no-eval': 'error',
'no-new-wrappers': 'error',
'no-shadow': 'off',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-unused-expressions': 'off',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-arrow/prefer-arrow-functions': 'error',
'prefer-const': 'error',
radix: 'error',
'spaced-comment': [
'error',
'always',
{
markers: ['/']
}
]
}
};
105 changes: 11 additions & 94 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,13 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: { project: './tsconfig.json' },
plugins: ['eslint-plugin-prefer-arrow', 'react', '@typescript-eslint'],
rules: {
'@typescript-eslint/class-literal-property-style': ['error', 'getters'],
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid'
},
{
selector: ['property', 'accessor'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'allow'
},
{
selector: ['variable', 'function'],
format: ['camelCase'],
leadingUnderscore: 'allow'
}
],
'@typescript-eslint/no-shadow': [
'error',
{
hoist: 'all'
}
],
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/restrict-template-expressions': ['error', { allowBoolean: true, allowNumber: true }],
'@typescript-eslint/unified-signatures': 'error',
'dot-notation': 'off',
eqeqeq: ['error', 'smart'],
'guard-for-in': 'error',
'linebreak-style': 'off',
'max-classes-per-file': ['error', 1],
'new-parens': ['error', 'always'],
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-empty-function': 'off',
'no-eval': 'error',
'no-new-wrappers': 'error',
'no-shadow': 'off',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-unused-expressions': 'off',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-arrow/prefer-arrow-functions': 'error',
'prefer-const': 'error',
radix: 'error',
'react/no-unstable-nested-components': ['warn', { allowAsProps: true }],
'spaced-comment': [
'error',
'always',
{
markers: ['/']
}
]
},
settings: {
react: {
version: 'detect'
}
const core = require('./core.js');
core.extends = [...core.extends, 'plugin:react/recommended'];
core.plugins = [...core.plugins, 'react'];
core.rules = {
'react/no-unstable-nested-components': ['warn', { allowAsProps: true }],
...core.rules
};
core.settings = {
react: {
version: 'detect'
}
};
module.exports = core;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/eslint-config-msgraph",
"version": "4.0.0",
"version": "4.1.0",
"description": "A sharable eslint config for Microsoft Graph web teams to use as a base set of linting rules",
"main": "index.js",
"files": [
Expand Down