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

[eslint-config-expo] eslint config for expo projects #27915

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/eslint-config-expo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
root: true,
extends: './default.js',
env: {
node: true
}
};
11 changes: 11 additions & 0 deletions packages/eslint-config-expo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## Unpublished

### 🛠 Breaking changes

### 🎉 New features

### 🐛 Bug fixes

### 💡 Others
21 changes: 21 additions & 0 deletions packages/eslint-config-expo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016-present Expo

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.
35 changes: 35 additions & 0 deletions packages/eslint-config-expo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# eslint-config-expo

Base ESLint config for Expo projects.
kadikraman marked this conversation as resolved.
Show resolved Hide resolved

## Installation

```sh
yarn add --dev eslint-config-expo
```

You will also need to install `eslint`:

```sh
yarn add --dev eslint
```

## Usage

Import this config into your own ESLint configuration using the `extends` option. ESLint checks both `package.json` and `.eslintrc.*` files for its configuration:
kadikraman marked this conversation as resolved.
Show resolved Hide resolved

### package.json
```js
{
"eslintConfig": {
"extends": "expo"
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
}
}
```

### .eslintrc.js
```js
module.exports = {
extends: 'expo',
};
```
55 changes: 55 additions & 0 deletions packages/eslint-config-expo/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const {
jsExtensions,
tsExtensions,
platformSubextensions,
computeExpoExtensions,
} = require('./utils/extensions');

const allExtensions = computeExpoExtensions(
[...jsExtensions, ...tsExtensions],
platformSubextensions,
);

module.exports = {
extends: [
'./utils/core.js',
'./utils/typescript.js',
'./utils/react.js',
'./utils/expo.js',
],
globals: {
__DEV__: false,
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
Atomics: false,
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
ErrorUtils: false,
FormData: false,
SharedArrayBuffer: false,
XMLHttpRequest: false,
alert: false,
cancelAnimationFrame: false,
cancelIdleCallback: false,
clearImmediate: false,
clearInterval: false,
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
clearTimeout: false,
fetch: false,
navigator: false,
process: false,
requestAnimationFrame: false,
requestIdleCallback: false,
setImmediate: false,
setInterval: false,
setTimeout: false,
window: false,
},
settings: {
'import/extensions': allExtensions,
'import/resolver': {
node: { extensions: allExtensions },
},
},
overrides: [
{
files: ['*.web.*'],
env: { browser: true },
},
],
};
42 changes: 42 additions & 0 deletions packages/eslint-config-expo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "eslint-config-expo",
"version": "7.0.0",
"description": "Eslint config for Expo apps",
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
"main": "default.js",
"scripts": {
"lint": "eslint ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo.git",
"directory": "packages/eslint-config-expo"
},
"keywords": [
"eslint-config",
"expo",
"react-native"
],
"files": [
"README.md",
"default.js",
"utils"
],
"author": "Expo",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"homepage": "https://github.com/expo/expo/tree/main/packages/eslint-config-expo",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
"eslint-plugin-expo": "^0.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react-hooks": "^4.6.0"
},
"peerDependencies": {
"eslint": ">=8.10"
}
}
178 changes: 178 additions & 0 deletions packages/eslint-config-expo/utils/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
const { jsExtensions } = require('./extensions');

module.exports = {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2022,
ecmaFeatures: { impliedStrict: true, jsx: true },
},
env: { es2022: true, jest: true },
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
globals: {
console: false,
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
exports: false,
global: false,
module: false,
require: false,
},
plugins: ['import', 'expo'],
rules: {
'array-bracket-spacing': ['warn', 'never'],
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'arrow-spacing': ['warn', { before: true, after: true }],
curly: ['warn', 'all'],
'block-spacing': ['warn', 'always'],
'comma-dangle': ['warn', 'always-multiline'],
'comma-spacing': ['warn', { before: false, after: true }],
'comma-style': ['warn', 'last'],
'computed-property-spacing': ['warn', 'never'],
'constructor-super': 'warn',
'dot-location': ['warn', 'property'],
'eol-last': 'warn',
eqeqeq: ['warn', 'smart'],
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'func-call-spacing': ['warn', 'never'],
'generator-star-spacing': ['warn', 'after'],
'getter-return': 'warn',
'jsx-quotes': ['warn', 'prefer-double'],
'new-parens': 'warn',
'no-alert': 'off',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-array-constructor': 'warn',
'no-caller': 'warn',
'no-case-declarations': 'warn',
'no-compare-neg-zero': 'warn',
'no-cond-assign': 'warn',
'no-const-assign': 'error',
'no-constant-condition': ['warn', { checkLoops: false }],
'no-control-regex': 'off',
'no-debugger': 'warn',
'no-delete-var': 'error',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-empty-character-class': 'warn',
'no-empty-pattern': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-eval': 'warn',
'no-ex-assign': 'warn',
'no-extend-native': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-extra-bind': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-extra-boolean-cast': 'warn',
'no-extra-semi': 'warn',
'no-fallthrough': 'warn',
'no-floating-decimal': 'warn',
'no-func-assign': 'error',
'no-global-assign': 'warn',
'no-implied-eval': 'warn',
'no-inner-declarations': 'warn',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'warn',
'no-iterator': 'warn',
'no-label-var': 'warn',
'no-labels': ['warn', { allowLoop: true, allowSwitch: true }],
'no-lone-blocks': 'warn',
'no-multi-assign': 'warn',
'no-new': 'warn',
'no-new-func': 'warn',
'no-new-object': 'warn',
'no-new-symbol': 'error',
'no-obj-calls': 'warn',
'no-octal': 'warn',
'no-octal-escape': 'warn',
'no-mixed-spaces-and-tabs': 'warn',
'no-proto': 'warn',
'no-redeclare': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-return-assign': 'warn',
'no-script-url': 'warn',
'no-self-assign': 'warn',
'no-self-compare': 'warn',
'no-sequences': 'warn',
'no-shadow-restricted-names': 'warn',
'no-sparse-arrays': 'warn',
'no-this-before-super': 'warn',
'no-throw-literal': 'warn',
'no-trailing-spaces': 'warn',
'no-undef': 'error',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-unexpected-multiline': 'warn',
'no-unneeded-ternary': 'warn',
'no-unreachable': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-unsafe-negation': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-unused-expressions': ['warn', { allowShortCircuit: true, enforceForJSX: true }],
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-unused-labels': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'no-unused-vars': [
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'warn',
{
vars: 'all',
args: 'none',
ignoreRestSiblings: true,
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
},
],
'no-useless-computed-key': 'warn',
'no-useless-concat': 'warn',
'no-useless-constructor': 'warn',
'no-useless-escape': 'warn',
'no-useless-rename': 'warn',
'no-useless-return': 'warn',
'no-var': 'warn',
'no-void': 'warn',
'no-whitespace-before-property': 'warn',
'no-with': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'object-shorthand': 'warn',
'operator-linebreak': ['warn', 'after', { overrides: { '?': 'before', ':': 'before' } }],
'prefer-const': ['warn', { destructuring: 'all', ignoreReadBeforeAssign: true }],
'prefer-promise-reject-errors': 'warn',
'prefer-rest-params': 'warn',
'prefer-spread': 'warn',
radix: 'warn',
'rest-spread-spacing': ['warn', 'never'],
semi: 'warn',
'semi-spacing': ['warn', { before: false, after: true }],
'semi-style': ['warn', 'last'],
'space-before-blocks': ['warn', 'always'],
'space-before-function-paren': ['warn', { anonymous: 'never', named: 'never' }],
'space-in-parens': ['warn', 'never'],
'space-infix-ops': 'warn',
'switch-colon-spacing': ['warn', { before: false, after: true }],
'template-curly-spacing': ['warn', 'never'],
'template-tag-spacing': ['warn', 'never'],
'unicode-bom': ['warn', 'never'],
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'use-isnan': 'error',
'valid-typeof': 'error',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'yield-star-spacing': ['warn', 'after'],
yoda: ['warn', 'never', { exceptRange: true }],

'import/default': 'off',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'import/export': 'error',
'import/first': 'warn',
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
'import/namespace': ['error', { allowComputed: true }],
'import/no-duplicates': 'error',
'import/order': [
'warn',
{
groups: [['builtin', 'external'], 'internal', ['parent', 'index', 'sibling']],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
},
],
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
},
settings: {
'import/extensions': jsExtensions,
'import/ignore': [
// react-native's main module is Flow, not JavaScript, and raises parse errors. Additionally,
// several other react-native-related packages still publish Flow code as their main source.
'node_modules[\\\\/]+@?react-native',
],
'import/resolver': {
node: { extensions: jsExtensions },
},
},
overrides: [
{
files: ['*.d.ts'],
rules: {
'import/order': 'off',
},
},
],
};
7 changes: 7 additions & 0 deletions packages/eslint-config-expo/utils/expo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
plugins: ['expo'],
rules: {
"expo/no-env-var-destructuring": ["error"],
"expo/no-dynamic-env-var": ["error"],
},
};
23 changes: 23 additions & 0 deletions packages/eslint-config-expo/utils/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const jsExtensions = ['.js', '.jsx'];
const tsExtensions = ['.ts', '.tsx', '.d.ts'];

const platformSubextensions = ['.android', '.ios', '.web', '.native'];

function computeExpoExtensions(baseExtensions, platformSubextensions) {
const expoExtensions = [];
for (const expo of ['.expo', '']) {
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
for (const platform of [...platformSubextensions, '']) {
for (const base of baseExtensions) {
expoExtensions.push(`${expo}${platform}${base}`);
}
}
}
return expoExtensions;
}

module.exports = {
jsExtensions,
tsExtensions,
platformSubextensions,
computeExpoExtensions,
};