Skip to content

Commit 296d78e

Browse files
pointlessonegdiggs
authored andcommitted
ESLint 3 preparation for master (#178)
* Monkey patch eslint, instead of modifying it - Add access to ESLint docs - Add support for parametrized Docker builds, building different versions of the documentation - Automatically detect which version of the docs we should be including * Use eslint-2.4.0 Fixes: npm WARN [email protected] requires a peer of eslint@^2.4.0 but none was installed. npm WARN [email protected] No license field. Cloning into 'eslint'... npm ERR! peer dep missing: eslint@^2.4.0, required by [email protected] npm ERR! code 1 error: pathspec 'vnull' did not match any file(s) known to git. * Comment loadPackage override Fixes: /usr/src/app/node_modules/meld/meld.js:67 if (typeof target[pointcut] === 'function') { ^ TypeError: Cannot read property 'loadPackage' of undefined at meld (/usr/src/app/node_modules/meld/meld.js:67:23) at Function.around (/usr/src/app/node_modules/meld/meld.js:436:12) at patcher (/usr/src/app/lib/eslint-patch.js:21:8) at Object.<anonymous> (/usr/src/app/bin/eslint.js:11:44) at Module._compile (module.js:397:26) at Object.Module._extensions..js (module.js:404:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:429:10) at startup (node.js:139:18) * Update babel-eslint to v6 Fixes #91 * Update dependencies ``` [email protected] -> [email protected] [email protected] -> [email protected] [email protected] -> [email protected] [email protected] -> [email protected] ``` * Add standard style plugin and shared config * Vendor additional Standard Style config packages (#102) Many users using [Standard Style][] also use these configuration packages when writing React/JSX. [Standard Style]: https://github.com/feross/standard This commit vendors the [eslint-config-standard-react] and [eslint-config-standard-jsx] packages. [eslint-config-standard-react]: https://github.com/feross/eslint-config-standard-react [eslint-config-standard-jsx]: https://github.com/feross/eslint-config-standard-jsx * Add eslint-config-google as available plugin * Added supporto for ESLint plugin Flowtype * Add support for eslint-config-angular * Add task to update npm-shrinkwrap.json * Update package.json (#112) eslint-2: Vendor eslint-plugin-angular package * add eslint-config-ember package * Switch base image to avoid Segfault Related to #111, a Segfault occurs when we hammer STDOUT with issues. Switching from alpine to a debian-based image seems to behave better in this scenario. * Update babel-eslint & eslint-flowtype We're a bit behind on these. Flowtype in particular has new rules we weren't supporting. Looks like we hadn't actually filled in the shrinkwrap file before now, either, so that's done. * Add --gecos "" to avoid adduser prompt * add hapi config support hapi eslint config is based on eslint-config-hapi and eslint-plugin-hapi packages * Add eslint-config-airbnb-base as a top-level dep eslint-config-airbnb-base is a transitive dependency of eslint-config-airbnb, but it is useful in its own right and should be included at the top level such that it has proper support in the eslint engine. * Update circle to trigger build * Upgrade to Node 6.5.0 * Update packages for ESLint 3 * eslint-3: Added ESLint plugins (#131) * eslint-3: Added ESLint plugins * Added appropriate eslint-plugin rule categorizations * Shifted category mappings to individual JSON file * Alphabetized ESLint plugin rule category mapping * Bump eslint to 3.6.1 & eslint-plugin-import to 1.16.0 (#136) The eslint bump was necessitated by `airbnb-config-base` wanting it. There's also a 2.0.0 of `eslint-plugin-import` available, but attempting to jump that far gave some peer package errors, so maybe we can't support that yet. * Support eslint-plugin-ember-suave. (#140) * Allow ignoring warnings from configuration. * Add CONTRIBUTING.md. The file, for now, shows how to create a local engine image for testing. * Add ignore_warnings to README As requested in #144. * Update README.md * Update project README - Update project/documentation links - Use open source Code Climate badge - Hard-wrap text - Fix YAML identation * Upgrade ESLint & some packages * We're several point releases behind on ESLint * After updating just that, I got some errors from shrinkwrap for two other packages we support, so I upgraded those too. * Add support for eslint-plugin-react-intl plugin (#154) * chore(packages): upgrade eslint * docs(CONTRIBUTING): fix .codeclimate.yml example * feat(config): add eslint-config-simplifield * Switch to yarn for installing dependencies This seems more intuitive to me today, and I hope will make it easier for contributors who want to add or upgrade plugins. Note: this is using nightly yarn, because there's a fix for Circle CI + Docker + Yarn compatibility that is made but not officially released yet. We can switch to stable yarn once 0.18.0 leaves pre-release. The fix was PR 1837 on the Yarn repo. * Upgrade eslint-config-google to 0.7.1 * Add eslint-plugin-meteor Close #155 Just ran: `bin/yarn add eslint-plugin-meteor` * Add eslint-plugin-immutable `bin/yarn add eslint-plugin-immutable` * Add eslint-plugin-import-order `bin/yarn add eslint-plugin-import-order` * Add eslint-plugin-jasmine `bin/yarn add eslint-plugin-jasmine` * Add eslint-config-semistandard `bin/yarn add eslint-config-semistandard` * Yarn add eslint-config-react-app Yarn upgrade babel-eslint ^7.0.0 Yarn upgrade eslint-plugin-flowtype to ^2.21.0 Yarn upgrade eslint-plugin-import to ^2.0.1 Yarn upgrade eslint-plugin-jsx-a11y to ^2.2.3 Yarn upgrade eslint-plugin-react to ^6.4.1 * added eslint-plugin-xogroup plugin * Upgrade eslint ``` make bin/yarn upgrade eslint ``` We'd like to pull in a fix for a bug that prevents using this rule: http://eslint.org/docs/2.0.0/rules/generator-star-spacing * add support for eslint prettier plugin * Add config upgrader Automatically upgrade pre-ESLint 3 config to ESLint 3-compatible format. * Fix null-config issue with upgrader When upgrader encountered a project that had no .eslintrc* but had an unrelated package.json that had no ESLint-related options in it an exception was thrown.
1 parent 3edd767 commit 296d78e

18 files changed

+2556
-1521
lines changed

.codeclimate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ engines:
99
ratings:
1010
paths:
1111
- bin/eslint.js
12-
- lib/checks.js
12+
- lib/*.js
1313
exclude_paths:
1414
- "node_modules/**"
1515
- "test/**"

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"node": true,
4-
"mocha": true
4+
"mocha": true,
5+
"es6": true
56
},
67
"rules": {
78
"block-spacing": 2,

CONTRIBUTING.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing
2+
3+
## Adding and upgrading plugins
4+
5+
When adding or upgrading a plugin, we should see changes in both `package.json`
6+
and `yarn.lock`.
7+
8+
Make sure to run `make image` before running these commands.
9+
10+
Add a plugin:
11+
12+
```
13+
bin/yarn add eslint-config-google
14+
```
15+
16+
Upgrade a plugin:
17+
18+
```
19+
bin/yarn upgrade eslint-config-google
20+
```
21+
22+
## Testing Changes
23+
24+
Changes made to the engine can be tested locally.
25+
26+
1. Install [the CodeClimate CLI](https://github.com/codeclimate/codeclimate).
27+
1. Create the image (customizing the `IMAGE_NAME` as needed):
28+
```bash
29+
IMAGE_NAME=codeclimate/codeclimate-eslint-test make image
30+
```
31+
1. Add the engine to your test `.codeclimate.yml`:
32+
```yaml
33+
engines:
34+
eslint-test:
35+
enabled: true
36+
```
37+
1. Run analyze via the CLI:
38+
```bash
39+
codeclimate analyze --dev
40+
```

Dockerfile

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
FROM mhart/alpine-node:5.4
1+
FROM node:6.5.0-slim
22
MAINTAINER Code Climate <[email protected]>
33

44
WORKDIR /usr/src/app
5-
COPY npm-shrinkwrap.json /usr/src/app/
6-
COPY package.json /usr/src/app/
5+
COPY package.json yarn.lock /usr/src/app/
76

8-
RUN apk --update add git && \
9-
npm install && \
10-
apk del --purge git
7+
RUN apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg && \
8+
echo "deb http://nightly.yarnpkg.com/debian/ nightly main" | tee /etc/apt/sources.list.d/yarn-nightly.list && \
9+
apt-get update && \
10+
apt-get install -y git jq yarn && \
11+
yarn install && \
12+
git clone https://github.com/eslint/eslint.git && \
13+
ESLINT_DOCS_VERSION=`npm -j ls eslint | jq -r .dependencies.eslint.version` && \
14+
cd eslint && \
15+
git checkout v$ESLINT_DOCS_VERSION && \
16+
cd .. && \
17+
mkdir -p /usr/src/app/lib/docs/rules/ && \
18+
cp ./eslint/docs/rules/* /usr/src/app/lib/docs/rules/ && \
19+
rm -rf eslint && \
20+
apt-get purge -y git jq && \
21+
apt-get autoremove -y
1122

12-
RUN adduser -u 9000 -D app
23+
RUN adduser -u 9000 --gecos "" --disabled-password app
1324
COPY . /usr/src/app
1425
RUN chown -R app:app /usr/src/app
1526

README.md

+46-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
# Code Climate ESLint Engine
22

3-
[![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate-eslint/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/codeclimate-eslint)
3+
[![Code Climate][badge]][repo]
44

5-
`codeclimate-eslint` is a Code Climate engine that wraps [ESLint](https://github.com/eslint/eslint). You can run it on your command line using the Code Climate CLI, or on our hosted analysis platform.
5+
[badge]: https://codeclimate.com/github/codeclimate/codeclimate-eslint/badges/gpa.svg
6+
[repo]: https://codeclimate.com/repos/github/codeclimate-eslint
67

7-
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. It can be configured using a [configuration file](https://github.com/eslint/eslint#usage).
8+
`codeclimate-eslint` is a Code Climate engine that wraps [ESLint][]. You can run
9+
it on your command line using the Code Climate CLI, or on our hosted analysis
10+
platform.
11+
12+
ESLint is a tool for identifying and reporting on patterns found in
13+
ECMAScript/JavaScript code. It can be configured using a [configuration
14+
file][config].
15+
16+
[config]: http://eslint.org/docs/user-guide/configuring#using-configuration-files
817

918
### Installation
1019

11-
1. If you haven't already, [install the Code Climate CLI](https://github.com/codeclimate/codeclimate).
12-
2. Run `codeclimate engines:enable eslint`. This command both installs the engine and enables it in your `.codeclimate.yml` file.
13-
3. You're ready to analyze! Browse into your project's folder and run `codeclimate analyze`.
20+
1. If you haven't already, [install the Code Climate CLI][CLI]
21+
22+
2. Run `codeclimate engines:enable eslint`. This command both installs the
23+
engine and enables it in your `.codeclimate.yml` file
24+
25+
3. You're ready to analyze! Browse into your project's folder and run
26+
`codeclimate analyze`
27+
28+
[cli]: https://github.com/codeclimate/codeclimate
29+
30+
### Configuration
31+
32+
#### `ignore_warnings`
33+
34+
By default, this engine will emit both ESLint errors and warnings as Code
35+
Climate issues. If you prefer, you can ignore warning-level violations by
36+
setting the `ignore_warnings` configuration option:
37+
38+
```yaml
39+
eslint:
40+
enabled: true
41+
config:
42+
ignore_warnings: true
43+
```
1444
1545
### Need help?
1646
17-
For help with ESLint, [check out their documentation](https://github.com/eslint/eslint).
47+
For help with ESLint, [check out their documentation][eslint-docs].
48+
49+
If you're running into a Code Climate issue, first look over this project's
50+
[GitHub Issues][issues], as your question may have already been covered. If not,
51+
[go ahead and open a support ticket with us][help].
52+
53+
[issues]: https://github.com/codeclimate/codeclimate-eslint/issues
54+
[help]: https://codeclimate.com/help
1855
19-
If you're running into a Code Climate issue, first look over this project's [GitHub Issues](https://github.com/codeclimate/codeclimate-eslint/issues), as your question may have already been covered. If not, [go ahead and open a support ticket with us](https://codeclimate.com/help).
56+
[eslint]: http://eslint.org
57+
[eslint-docs]: http://eslint.org/docs/user-guide/

bin/eslint.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ process.chdir(CODE_DIR);
88
var stdout = console.log;
99
console.log = console.error;
1010

11-
var CLIEngine = require("eslint").CLIEngine;
12-
var docs = require("eslint").docs;
11+
var eslint = require('../lib/eslint-patch')(require('eslint'));
12+
13+
var CLIEngine = eslint.CLIEngine;
14+
var docs = eslint.docs;
1315
var fs = require("fs");
1416
var glob = require("glob");
1517
var options = { extensions: [".js"], ignore: true, reset: false, useEslintrc: true };
1618
var cli; // instantiation delayed until after options are (potentially) modified
1719
var debug = false;
1820
var BatchSanitizer = require("../lib/batch_sanitizer");
21+
var ignoreWarnings = false;
22+
var ESLINT_WARNING_SEVERITY = 1;
1923
var checks = require("../lib/checks");
2024
var validateConfig = require("../lib/validate_config");
2125
var computeFingerprint = require("../lib/compute_fingerprint");
26+
const ConfigUpgrader = require("../lib/config_upgrader");
2227

2328
// a wrapper for emitting perf timing
2429
function runWithTiming(name, fn) {
@@ -172,6 +177,10 @@ runWithTiming("engineConfig", function () {
172177
options.ignorePath = userConfig.ignore_path;
173178
}
174179

180+
if (userConfig.ignore_warnings) {
181+
ignoreWarnings = true;
182+
}
183+
175184
if (userConfig.debug) {
176185
debug = true;
177186
}
@@ -207,6 +216,8 @@ function analyzeFiles() {
207216
var path = result.filePath.replace(/^\/code\//, "");
208217

209218
result.messages.forEach(function(message) {
219+
if (ignoreWarnings && message.severity === ESLINT_WARNING_SEVERITY) { return; }
220+
210221
var issueJson = buildIssueJson(message, path);
211222
process.stdout.write(issueJson + "\u0000\n");
212223
});
@@ -225,6 +236,10 @@ function analyzeFiles() {
225236
if (validateConfig(options.configFile)) {
226237
console.error("ESLint is running with the " + cli.getConfigForFile(null).parser + " parser.");
227238

239+
for (const line of ConfigUpgrader.upgradeInstructions(analysisFiles, process.cwd())) {
240+
console.error(line);
241+
}
242+
228243
analyzeFiles();
229244
} else {
230245
console.error("No rules are configured. Make sure you have added a config file with rules enabled.");

bin/yarn

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
IMAGE_NAME=${IMAGE_NAME:-codeclimate/codeclimate-eslint}
6+
docker run --rm --volume "$PWD:/usr/src/app" "$IMAGE_NAME" sh -c "cd /usr/src/app && yarn $*"

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test:
2020

2121
deployment:
2222
registry:
23-
branch: master
23+
branch: /master|channel\/[\w-]+/
2424
commands:
2525
- >
2626
docker run

0 commit comments

Comments
 (0)