Skip to content

Commit 44539c4

Browse files
committed
Initial commit
0 parents  commit 44539c4

13 files changed

+4230
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.eslintrc.js

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
parserOptions: {
3+
ecmaVersion: 2018,
4+
},
5+
env: {
6+
commonjs: true,
7+
es6: true,
8+
node: true,
9+
},
10+
extends: ["eslint:recommended", "plugin:eslint-plugin/recommended", "plugin:prettier/recommended"],
11+
plugins: ["eslint-plugin"],
12+
rules: {
13+
"eslint-plugin/meta-property-ordering": "error",
14+
"eslint-plugin/prefer-placeholders": "error",
15+
"eslint-plugin/test-case-property-ordering": "error",
16+
"eslint-plugin/test-case-shorthand-strings": "error",
17+
},
18+
};

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env
67+
.env.test
68+
69+
# parcel-bundler cache (https://parceljs.org/)
70+
.cache
71+
72+
# next.js build output
73+
.next
74+
75+
# nuxt.js build output
76+
.nuxt
77+
78+
# vuepress build output
79+
.vuepress/dist
80+
81+
# Serverless directories
82+
.serverless/
83+
84+
# FuseBox cache
85+
.fusebox/
86+
87+
# DynamoDB Local files
88+
.dynamodb/

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Appulate
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# eslint-plugin-appulate
2+
3+
Appulate’s ESLint rules.

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.rules = {
2+
"no-undef-blacklist": require("./rules/no-undef-blacklist.js.js"),
3+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const rule = require("../no-undef-blacklist");
2+
const { RuleTester } = require("eslint/lib/rule-tester");
3+
4+
const options = ["foo", "bar"];
5+
const parserOptions = {
6+
ecmaVersion: 2018,
7+
sourceType: "module",
8+
};
9+
const ruleTester = new RuleTester();
10+
11+
ruleTester.run("no-undef-blacklist", rule, {
12+
valid: [
13+
{ code: "import foo from 'foo'; foo();", options, parserOptions },
14+
{ code: "import bar from 'bar'; bar();", options, parserOptions },
15+
{ code: "import xyz from 'xyz'; xyz();", options, parserOptions },
16+
{ code: "xyz();", options, parserOptions },
17+
],
18+
invalid: [
19+
{
20+
code: "foo();",
21+
options,
22+
parserOptions,
23+
errors: [{ messageId: "undef", data: { name: "foo" }, type: "Identifier" }],
24+
},
25+
{
26+
code: "bar();",
27+
options,
28+
parserOptions,
29+
errors: [{ messageId: "undef", data: { name: "bar" }, type: "Identifier" }],
30+
},
31+
],
32+
});

lib/rules/no-undef-blacklist.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @fileoverview Rule to flag references to undeclared variables.
3+
* @copyright 2019 Appulate
4+
* @copyright JS Foundation and other contributors, https://js.foundation
5+
*/
6+
7+
/**
8+
* This rule is a fork of https://eslint.org/docs/rules/no-undef that adds an ability to specify a blacklist of identifiers.
9+
* Ideally, we wouldn't need this rule, because we could rely on TypeScript. But some typings, such as @types/jquery
10+
* or @types/knockout declare global variables (i.e. $) and TypeScript does not throw any errors when such a global
11+
* variable is used in the module without its import. The original no-undef rule works incorrectly in TypeScript files
12+
* because of the error https://github.com/typescript-eslint/typescript-eslint/issues/342, so we had to write our own
13+
* rule that accepts the list of certain problematic identifiers.
14+
*/
15+
16+
"use strict";
17+
18+
module.exports = {
19+
meta: {
20+
type: "problem",
21+
docs: {
22+
description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments",
23+
category: "Variables",
24+
},
25+
schema: {
26+
type: "array",
27+
items: {
28+
type: "string",
29+
},
30+
uniqueItems: true,
31+
minItems: 1,
32+
},
33+
messages: {
34+
undef: "'{{name}}' is not defined.",
35+
},
36+
},
37+
38+
create(context) {
39+
const blacklist = context.options;
40+
41+
return {
42+
"Program:exit"() {
43+
const globalScope = context.getScope();
44+
45+
globalScope.through.forEach(ref => {
46+
const { identifier } = ref;
47+
48+
if (blacklist.includes(identifier.name)) {
49+
context.report({
50+
node: identifier,
51+
messageId: "undef",
52+
data: identifier,
53+
});
54+
}
55+
});
56+
},
57+
};
58+
},
59+
};

package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@appulate/eslint-plugin",
3+
"version": "0.1.0",
4+
"description": "Appulate's ESLint rules",
5+
"repository": "appulate/eslint-plugin-appulate",
6+
"main": "lib/index.js",
7+
"license": "MIT",
8+
"files": [
9+
"lib",
10+
"!__tests__"
11+
],
12+
"keywords": [
13+
"eslint",
14+
"eslintplugin",
15+
"eslint-plugin",
16+
"linter",
17+
"lint",
18+
"appulate"
19+
],
20+
"scripts": {
21+
"lint": "eslint .",
22+
"test": "jest"
23+
},
24+
"engines": {
25+
"node": ">=10"
26+
},
27+
"peerDependencies": {
28+
"eslint": ">=5"
29+
},
30+
"devDependencies": {
31+
"eslint": "6.1.0",
32+
"eslint-config-prettier": "6.0.0",
33+
"eslint-plugin-eslint-plugin": "2.1.0",
34+
"eslint-plugin-prettier": "3.1.0",
35+
"jest": "24.9.0",
36+
"prettier": "1.18.2"
37+
}
38+
}

prettier.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
printWidth: 120,
3+
tabWidth: 4,
4+
useTabs: true,
5+
semi: true,
6+
singleQuote: false,
7+
trailingComma: "all",
8+
bracketSpacing: true,
9+
jsxBracketSameLine: false,
10+
};

0 commit comments

Comments
 (0)