Git Product home page Git Product logo

eslint4b's Introduction

eslint4b

npm version Downloads/month Build Status Dependency Status

ESLint which works in browsers.

๐Ÿ Goal

ESLint doesn't support browsers officially, but we can use it similar to the official online demo. This package provides the Linter class which is modified to work in browsers.

  • Eliminate the dependency to fs.
  • Eliminate the dynamic require()s.

This package is kept latest with cron jobs GitHub Actions provide.

๐Ÿ’ฟ Installation

Use npm to install.

npm install eslint4b

๐Ÿ“– Usage

Use a bundler such as Webpack. The eslint4b must be able to be bundled.

const Linter = require("eslint4b") // import Linter from "eslint4b"
const linter = new Linter();

// Verify a code.
// See the official document of the Linter class.
const messages = linter.verify(
    "var foo = 0",
    {
        rules: {
            semi: "error"
        }
    },
    { filename: "foo.js" }
);

Also, you can use the Linter class which doesn't include any core rules. It's lightweight than the full set.

// This Linter doesn't include any core rules.
const Linter = require("eslint4b/dist/linter")

// You can load core rules individually.
const { indent, quotes, semi } = require("eslint4b/dist/core-rules")
const linter = new Linter()
linter.defineRule("indent", indent)
linter.defineRule("quotes", quotes)
linter.defineRule("semi", semi)

๐Ÿ“ฐ Changelog

See GitHub releases.

If no description, it's the build of ESLint in the same version. It doesn't have any notable change.

โค๏ธ Contributing

Contributing is welcome.

Please use GitHub issues/PRs.

Development tools

  • npm test runs tests.
  • npm run build build ESLint which works in browsers.

eslint4b's People

Contributors

mysticatea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eslint4b's Issues

Problem trying to use with webpack

Hi,

I'm trying to use webpack to create a bundle that includes eslint4b to run in a WebWorker.

I have the following webpack.config.js:

{
    entry: path.resolve(__dirname, 'lib/rules/function-eslint/index.js'),
    output: {
        filename: 'nrlint-plugin-rules-function-eslint.js',
        path: path.resolve(__dirname, 'resources'),
        library: {
            name: ['nrlint','rules'],
            type: 'assign-properties'
        }
    },
    resolve: {
        fallback: {
            "assert": path.resolve(__dirname, 'lib/rules/function-eslint/empty.js'),
            "util":   false,
            "path":   false
        }
    },
    mode: 'production',
    target: ['webworker']
}

When I run webpack, I get multiple errors of the sort:

Module not found: Error: Can't resolve '@eslint/eslintrc/conf/environments' in '/Users/nol/code/node-red/nrlint/node_modules/eslint4b/dist'

This happens for:

  • @eslint/eslintrc/conf/environments'
  • @eslint/eslintrc/lib/shared/config-ops
  • @eslint/eslintrc/lib/shared/config-validator

I have found I need to have the full eslint installed as a dependency of my own module for the webpack to work. Is that expected?

Support ESLint 8.x

ESLint v8.0.0 is released ๐ŸŽ‰

It would be awesome to have official ESLint 8 support. ๐Ÿ‘Š
I'm happy to help where I can of course ๐Ÿ™‚

Distributing a self-contained script

Firstly, thanks for doing this. Before I found it, running ESLint in the browser seemed impossible. With this, it only seems painful.

After several hours of messing around with Rollup and Babel, I managed to create an ESLint file that I can load in IE11. It's a 1.3mb monster that I'd rather not check into version control, but I'm also loath to include this entire build process with all the plugins that it requires in my package's build process. So I'm leaning towards stuffing it into a separate npm package. But that package already sort of exists here, and it seems you even have a way to keep it up to date.

Would you consider including a full, self-contained built artifact in this package? Or adjust your scripts to publish a second package with such a file?

How can i use with code contains async function

How to configure this module so that it does not detect an error in the following code:
async function* main() {/* do something with await*/}

I got this error message (with linter.verify()):

{
  ruleId: null, 
  fatal: true, 
  severity: 2, 
  message: 
  "Parsing error: Unexpected token function"
line: 1, column: 7
}

I think that i need to set ESLint parserOptions on another ECMAversion but I don't know about that.

Thanks

linter.verify hangs if code contains \n and no-useless-escape is enabled

If the code that is passed to linter.verify contains \\n in a string, and no-useless-escape is enabled, the function hangs and cpu usage hits 100%.

Passing the exact same code through eslint (7.32.0) does not.

The following code can be used to reproduce:

const Linter = require('eslint4b');
const linter = new Linter();

var defaultConfig = {
    "env": {
        "es2021": true
    },
    "parserOptions": {
        "ecmaVersion": 12
    },
    "rules": {
        "no-useless-escape": "error",
    }
}

linter.verify('const a = "\\n"', defaultConfig)

How to use custom parser? babel-parser

I'm trying to integrate eslint4b with codemirror linting addon using codemirror-lint-eslint library.

I keep getting this error

image

This is the configuration

var defaultConfig = {
    "ecmaFeatures": {},
    "env": {
        "browser": true,
        "node": true,
        "amd": false,
        "mocha": false,
        "jasmine": false,
        "es2021": true
    },
    "globals": {
      "browser": true,
      "node": true
    },
    "extends": [
      "plugin:react/recommended",
      "airbnb",
      "plugin:prettier/recommended",
      "plugin:import/errors",
      "plugin:import/warnings",
      "plugin:react-hooks/recommended",
      "plugin:react-redux/recommended",
      "plugin:promise/recommended",
      "plugin:jsx-a11y/recommended"
    ],
    "parser": "babel-eslint",
    "parserOptions": {
      "ecmaFeatures": {
        "jsx": true
      },
      "ecmaVersion": 12,
      "sourceType": "module"
    },
    "plugins": ["react", "simple-import-sort", "better-styled-components"],
    "rules": {
       // ... eslint rules
    }
  }

This is how I use eslint4b
image

Any pointer will be really helpful.

Thank you

Support for ES6 Import and Typescript Definition File

Thanks for making linting possible in the browser!

In my typescript project I am using ES6 style import, and it's very challenging for me to get eslint4b to work.

Ideally I want to have:

import { Linter } from "eslint4b"; 

...
this.linter = new Linter();
this.linter.verify(...);
...

But apparently import("eslint4b") is returning a promise and it messes up all the Type Definitions I manually copy/pasted from the original eslint's .d.ts file.

Thanks. :)

PS. How can I get other classes like SourceCode?

Confused about bundle eslint-plugin

I forked the repo attempting to extend typescript-eslint
When I run yarn build, rollup occurs error

'@typescript-eslint/eslint-plugin' is imported by scripts/shim/test2.js, but could not be resolved โ€“ treating it as an external dependency

the path is valid but why rollup could not resolve it

import {rules} from "@typescript-eslint/eslint-plugin"
function testMethod (){
    console.log("test",rules);
}
export default testMethod;

Invitation to move to official `eslint-community` org

We would love to have this repo added to the official @eslint-community organization on GitHub.

As you can read in the '@eslint-community GitHub organization' RFC, the goal of this new org is to have a place where community members can help ensure widely depended upon ESLint related packages stay up to date with newer ESLint releases and doesn't hold the wider community back without depending on one person's GitHub/npm account.

Since this plugin is currently unmaintained (the latest commit is 1y+ old & the latest interaction is 1y+ old as well), we'd love you โ€”@mysticateaโ€” to transfer this repo to a better home, so you're welcome to transfer this repository to the new org.

Infinite loop with "no-useless-escape" rule

I have confirmed with eslint4b v7.20.0.

The following source code is the source code for at 25,907 line of the eslint4b/dist/core-rules.js file causing the infinite loop.

        while (match = /\\[^\d]/gu.exec(value)) {
          validateString(node, match);
        }

In the original source code, the regular expression correctly uses one instance, so it doesn't go into an infinite loop.

https://github.com/eslint/eslint/blob/87c43a5d7ea2018cffd6d9b5c431ecb60caaf0d6/lib/rules/no-useless-escape.js#L210-L215

                const pattern = /\\[^\d]/gu;
                let match;

                while ((match = pattern.exec(value))) {
                    validateString(node, match);
                }

I think it's probably a build system bug, but I opened an issue here because I don't know which build system is wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.