npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bam.tech/eslint-plugin

v6.0.0

Published

eslint plugin for bam projects

Downloads

2,721

Readme

ESLint plugin by BAM

This project is an ESLint plugin that gathers all the rules, plugins and parsers that should be used in any new react-native BAM project.

The list of rules and configuration details can be found here.

Quick Setup

Install the plugin and its peer dependencies:

yarn add @bam.tech/eslint-plugin --dev
npx install-peerdeps @bam.tech/eslint-plugin --dev --yarn

Then update your .eslintrc config file:

// .eslintrc
{
  "extends": "plugin:@bam.tech/recommended",
  "overrides": [
    {
      "files": ["*.test.tsx", "*.test.ts"],
      "extends": "plugin:@bam.tech/tests"
    }
  ]
}

Setting up the plugin on a monorepo

Update your .vscode/settings.json by adding the directories of apps using the plugin:

// .vscode/settings.json
{
  ...
  "eslint.workingDirectories": [
    "apps/yourFirstApp",
    "apps/yourSecondApp"
    ]
}

Handling files ignored by TypeScript

The plugin default behavior is to use TypeScript configuration to lint all TypeScript files. However, in your project, there may be files you've chosen to ignore with TypeScript. It's advisable to also disable ESLint checking for these files. To achieve this, add the files you want to ignore with ESLint in the overrides section of your eslintrc.js. Below is an example illustrating this. The configuration for mock files is overridden: the TypeScript parser is removed, and the behavior of the @typescript-eslint/return-await rule is modified.

overrides: [
  {
    files: ["mocks/**/*"],
    parserOptions: {
      project: null,
    },
    rules: {
      "@typescript-eslint/return-await": "off",
    },
  },
];

⚠️ React version

With the introduction of React 18, it's no longer necessary to import React in your JSX files. The ESLint plugin is configured for React version 18 and above, so you won't encounter any errors. However, TypeScript will generate an error if it isn't configured correctly. To resolve this, simply add "jsx": "react-native" to your tsconfig.json file.

If your project is using a version of React that's below 18, iyou should upgrade to a newer version of React. If upgrading isn't an option, here's the situation: importing React in your JSX files remains mandatory, but ESLint won't flag any errors, even though it should. This is due to the plugin configuration; the recommended configuration extends the plugin react/jsx-runtime, which disables the following rules:

  • 'react/jsx-uses-react': "error"
  • 'react/react-in-jsx-scope': "error"

These rules are crucial as they trigger an error when React is not in scope. Therefore, you'll need to include them in the rules section of your .eslintrc.js file to ensure an error is flagged whenever someone omits the import for React.

Remember, the recommended solution is to upgrade to a newer version of React. This advice should only be disregarded in exceptional circumstances where upgrading React is not feasible.

Shareable configurations

This plugin exports multiple configurations that can be used in your .eslintrc config file:

| Name | Description | | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | @bam.tech/recommended | The recommended config for all projects | | @bam.tech/tests | The recommended config for test files. By default this applies to every file: put it in an overrides to filter on your test files. | | @bam.tech/a11y | [beta] Eslint config to check for accessibility. Still in beta to not break existing projects, but will be merged into the recommended config in the future. |

These configs need some peer dependencies. You can list them with:

npm info "@bam.tech/esling-plugin" peerDependencies

If you use npm >= 5 you can automatically install them by running:

npx install-peerdeps @bam.tech/eslint-config -D

Eslint rules

This plugin exports some custom rules that you can optionally use in your project:

💼 Configurations enabled in.
🧪 Set in the tests configuration.
🔧 Automatically fixable by the --fix CLI option.

| Name | Description | 💼 | 🔧 | | :------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- | :-- | :-- | | await-user-event | Enforces awaiting userEvent calls | 🧪 | 🔧 | | prefer-user-event | Enforces usage of userEvent over fireEvent in tests. | | 🔧 | | require-named-effect | Enforces the use of named functions inside a useEffect | | |

To use a rule, just declare it in your .eslintrc:

// .eslintrc
{
  "plugins": ["@bam.tech"],
  "rules": {
    "@bam.tech/require-named-effect": "error"
  }
}

Tip: if your config is already extended from a @bam.tech config, you don't need to declare the plugin.

How to customize?

You can still customize your ESLint config by adding other configurations, plugins and rules to your .eslintrc config file.

Contribute

If you find a useful rule that you feel every project at BAM should use, feel free to contribute.