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

🏗 Clean up .eslintignore #22411

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Output directories
node_modules
build
build/**
dist/**
dist.3p/**
dist.tools/**
firebase/**
out/**
test/coverage/**

# Code directories
**/*.extern.js
build-system/tasks/visual-diff/snippets/*.js
build-system/babel-plugins/**/fixtures/**/*.js
build-system/app-index/test/**/*.js
dist
dist.3p
dist.tools
out
examples
firebase
third_party
test/coverage
**/*.extern.js
validator/
eslint-rules
babel.config.js
karma.conf.js
testing/local-amp-chrome-extension
extensions/amp-a4a/0.1/test/testdata
examples/**
extensions/amp-a4a/0.1/test/testdata/**
extensions/amp-access/0.1/access-expr-impl.js
extensions/amp-animation/0.1/parsers/css-expr-impl.js
extensions/amp-bind/0.1/bind-expr-impl.js
testing/local-amp-chrome-extension/**
third_party/**
validator/**
21 changes: 13 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

'use strict';

const {isTravisBuild} = require('./build-system/travis');
const minimist = require('minimist');
const {isTravisBuild} = require('./build-system/travis');
const argv = minimist(process.argv.slice(2));

// eslint-disable-next-line amphtml-internal/no-module-exports
module.exports = function(api) {
api.cache(true);
// Single pass builds do not use any of the default settings below.
Expand All @@ -37,14 +38,18 @@ module.exports = function(api) {
}
return {
'presets': [
['@babel/env', {
'modules': 'commonjs',
'loose': true,
'targets': {
'browsers': isTravisBuild() ?
['Last 2 versions', 'safari >= 9'] : ['Last 2 versions'],
[
'@babel/env',
{
'modules': 'commonjs',
'loose': true,
'targets': {
'browsers': isTravisBuild()
? ['Last 2 versions', 'safari >= 9']
: ['Last 2 versions'],
},
},
}],
],
],
'compact': false,
'sourceType': 'module',
Expand Down
1 change: 0 additions & 1 deletion build-system/eslint-rules/await-expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ function hasAwaitParent(node) {
}
return false;
}

22 changes: 5 additions & 17 deletions build-system/eslint-rules/closure-type-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ module.exports = function(context) {
fixable: 'code',
},
Program: function() {
const comments =
/** @type {!Array<!EslintNodeDef>} */ (sourceCode.getAllComments());
const comments = /** @type {!Array<!EslintNodeDef>} */ (sourceCode.getAllComments());
comments
.map(node => parseClosureComments(context, node))
.forEach(comment => checkClosureComments(context, comment));
.map(node => parseClosureComments(context, node))
.forEach(comment => checkClosureComments(context, comment));
},
};
};
Expand Down Expand Up @@ -108,12 +107,7 @@ function checkClosureComments(context, closureComment) {
}

/** @enum {string} */
const PRIMITIVE_WRAPPER_NAMES = [
'Boolean',
'Number',
'String',
'Symbol',
];
const PRIMITIVE_WRAPPER_NAMES = ['Boolean', 'Number', 'String', 'Symbol'];

/**
* Disallowed primitives wrappers, from
Expand Down Expand Up @@ -179,12 +173,7 @@ function checkNonNullableNodes(context, node, astNode) {
* so we don't add them to this list.
* @enum {string}
*/
const NON_NULLABLE_PRIMITIVE_NAMES = [
'boolean',
'number',
'string',
'symbol',
];
const NON_NULLABLE_PRIMITIVE_NAMES = ['boolean', 'number', 'string', 'symbol'];

/**
* True if the given name matches a primitive type
Expand Down Expand Up @@ -220,4 +209,3 @@ function reportNonNullablePrimitive(context, node, name) {
},
});
}

12 changes: 8 additions & 4 deletions build-system/eslint-rules/dict-string-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ module.exports = function(context) {
if (arg1.type !== 'ObjectExpression') {
context.report({
node,
message: 'calls to `dict` must have an Object Literal ' +
'Expression as the first argument',
message:
'calls to `dict` must have an Object Literal ' +
'Expression as the first argument',
});
return;
}
Expand All @@ -42,8 +43,11 @@ function checkNode(node, context) {
if (!prop.key.raw && !prop.computed) {
context.report({
node,
message: 'Found: ' + prop.key.name + '. The keys of the Object ' +
'Literal Expression passed into `dict` must have string keys.',
message:
'Found: ' +
prop.key.name +
'. The keys of the Object ' +
'Literal Expression passed into `dict` must have string keys.',
});
}
checkNode(prop.value, context);
Expand Down
25 changes: 15 additions & 10 deletions build-system/eslint-rules/enforce-private-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,31 @@ module.exports = function(context) {
* @return {boolean}
*/
function isThisMemberExpression(node) {
return node.type == 'MemberExpression' &&
node.object.type == 'ThisExpression';
return (
node.type == 'MemberExpression' && node.object.type == 'ThisExpression'
);
}
return {
MethodDefinition: function(node) {
if (hasPrivateAnnotation(node.leadingComments) &&
!hasExplicitNoInline(node.key.name) &&
!hasTrailingUnderscore(node.key.name)) {
if (
hasPrivateAnnotation(node.leadingComments) &&
!hasExplicitNoInline(node.key.name) &&
!hasTrailingUnderscore(node.key.name)
) {
context.report({
node,
message: 'Method marked as private but has no trailing underscore.',
});
}
},
AssignmentExpression: function(node) {
if (node.parent.type == 'ExpressionStatement' &&
hasPrivateAnnotation(node.parent.leadingComments) &&
isThisMemberExpression(node.left) &&
!hasExplicitNoInline(node.left.property.name) &&
!hasTrailingUnderscore(node.left.property.name)) {
if (
node.parent.type == 'ExpressionStatement' &&
hasPrivateAnnotation(node.parent.leadingComments) &&
isThisMemberExpression(node.left) &&
!hasExplicitNoInline(node.left.property.name) &&
!hasTrailingUnderscore(node.left.property.name)
) {
context.report({
node,
message: 'Property marked as private but has no trailing underscore.',
Expand Down
45 changes: 26 additions & 19 deletions build-system/eslint-rules/html-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,41 @@ module.exports = function(context) {
function htmlCannotBeCalled(node) {
context.report({
node,
message: 'The html helper MUST NOT be called directly. ' +
'Instead, use it as a template literal tag: ``` html`<div />` ```',
message:
'The html helper MUST NOT be called directly. ' +
'Instead, use it as a template literal tag: ``` html`<div />` ```',
});
}

function htmlForUsage(node) {
const {parent} = node;
if (parent.type === 'TaggedTemplateExpression' &&
parent.tag === node) {
if (parent.type === 'TaggedTemplateExpression' && parent.tag === node) {
return htmlTagUsage(parent);
}

if (parent.type === 'VariableDeclarator' &&
parent.init === node &&
parent.id.type === 'Identifier' &&
parent.id.name === 'html') {
if (
parent.type === 'VariableDeclarator' &&
parent.init === node &&
parent.id.type === 'Identifier' &&
parent.id.name === 'html'
) {
return;
}

if (parent.type === 'AssignmentExpression' &&
parent.right === node &&
parent.left.type === 'Identifier' &&
parent.left.name === 'html') {
if (
parent.type === 'AssignmentExpression' &&
parent.right === node &&
parent.left.type === 'Identifier' &&
parent.left.name === 'html'
) {
return;
}

context.report({
node,
message: 'htmlFor result must be stored into a variable ' +
'named "html", or used as the tag of a tagged template literal.',
message:
'htmlFor result must be stored into a variable ' +
'named "html", or used as the tag of a tagged template literal.',
});
}

Expand All @@ -57,8 +62,9 @@ module.exports = function(context) {
if (quasi.expressions.length !== 0) {
context.report({
node,
message: 'The html template tag CANNOT accept expression. ' +
'The template MUST be static only.',
message:
'The html template tag CANNOT accept expression. ' +
'The template MUST be static only.',
});
}

Expand All @@ -74,9 +80,10 @@ module.exports = function(context) {
if (/<(html|body|head)/i.test(string)) {
context.report({
node: template,
message: 'It it not possible to generate HTML, BODY, or' +
' HEAD root elements. Please do so manually with' +
' document.createElement.',
message:
'It it not possible to generate HTML, BODY, or' +
' HEAD root elements. Please do so manually with' +
' document.createElement.',
});
}

Expand Down
11 changes: 8 additions & 3 deletions build-system/eslint-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ const fs = require('fs');
const path = require('path');

const rules = {};
const ruleFiles = fs.readdirSync(__dirname).filter(ruleFile =>
!['index.js', 'node_modules', 'package.json', '.eslintrc']
.includes(ruleFile));
const ruleFiles = fs
.readdirSync(__dirname)
.filter(
ruleFile =>
!['index.js', 'node_modules', 'package.json', '.eslintrc'].includes(
ruleFile
)
);
ruleFiles.forEach(function(ruleFile) {
const rule = ruleFile.replace(path.extname(ruleFile), '');
rules[rule] = require(path.join(__dirname, rule));
Expand Down
16 changes: 6 additions & 10 deletions build-system/eslint-rules/no-duplicate-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ module.exports = {
},

create(context) {
const imports = new Map();
const imports = new Map();

return {
"Program:exit": function() {
imports.forEach((imports) => {
'Program:exit': function() {
imports.forEach(imports => {
const original = imports[0];

for (let i = 1; i < imports.length; i++) {
Expand All @@ -59,11 +59,8 @@ module.exports = {
}
}

return [
fixer.remove(node),
fixer.insertTextAfter(last, text),
];
}
return [fixer.remove(node), fixer.insertTextAfter(last, text)];
},
});
}
});
Expand All @@ -78,7 +75,6 @@ module.exports = {
return;
}
for (let i = 0; i < specifiers.length; i++) {
const spec = specifiers[i];
if (specifiers[i].type === 'ImportNamespaceSpecifier') {
return;
}
Expand All @@ -91,7 +87,7 @@ module.exports = {
}

nodes.push(node);
}
},
};
},
};
11 changes: 7 additions & 4 deletions build-system/eslint-rules/no-es2015-number-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ function isInvalidProperty(property) {
module.exports = function(context) {
return {
MemberExpression: function(node) {
if (node.object.name == 'Number' &&
isInvalidProperty(node.property.name)) {
if (
node.object.name == 'Number' &&
isInvalidProperty(node.property.name)
) {
context.report({
node,
message: 'no ES2015 "Number" methods and properties allowed to be ' +
'used.',
message:
'no ES2015 "Number" methods and properties allowed to be ' +
'used.',
});
}
},
Expand Down
20 changes: 11 additions & 9 deletions build-system/eslint-rules/no-export-side-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ module.exports = function(context) {
const {declaration} = node;
if (declaration.type === 'VariableDeclaration') {
declaration.declarations
.map(function(declarator) {
return declarator.init;
}).filter(function(init) {
return init && /(?:Call|New)Expression/.test(init.type);
}).forEach(function(init) {
context.report({
node: init,
message: 'Cannot export side-effect',
});
.map(function(declarator) {
return declarator.init;
})
.filter(function(init) {
return init && /(?:Call|New)Expression/.test(init.type);
})
.forEach(function(init) {
context.report({
node: init,
message: 'Cannot export side-effect',
});
});
}
} else if (node.specifiers) {
context.report({
Expand Down
Loading