Skip to content

Tweak linting, tests, and CI #23

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

Merged
merged 4 commits into from
Oct 14, 2020
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
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
es2017: true,
node: true,
},
};
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on: [push, pull_request]

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14'
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ci-modules-${{ hashFiles('**/yarn.lock') }}
- name: install dependencies
run: yarn install --frozen-lockfile --non-interactive
- name: linting
run: yarn lint

test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '10', '12', '14' ]
name: Node ${{ matrix.node }} tests
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ci-modules-${{ hashFiles('**/yarn.lock') }}
- name: install dependencies
run: yarn install --frozen-lockfile --non-interactive
- name: test
run: yarn test
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
};
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

22 changes: 9 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var requireIndex = require("requireindex");
'use strict';

//------------------------------------------------------------------------------
// Plugin Definition
//------------------------------------------------------------------------------


// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + "/rules");



module.exports = {
rules: {
'no-const-outside-module-scope': require('./rules/no-const-outside-module-scope'),
'no-empty-yuidoc-code-blocks': require('./rules/no-empty-yuidoc-code-blocks'),
'require-yuidoc-access': require('./rules/require-yuidoc-access'),
'require-yuidoc-code-block-type': require('./rules/require-yuidoc-code-block-type'),
},
};
20 changes: 12 additions & 8 deletions lib/rules/no-const-outside-module-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
meta: { fixable: 'code', schema: [] },
create(context) {
return {
VariableDeclaration: function(node) {
VariableDeclaration: function (node) {
if (node.kind !== 'const') {
return;
}
Expand All @@ -14,8 +14,12 @@ module.exports = {
return;
}

if (node.parent && node.parent.type === 'ExportNamedDeclaration' &&
node.parent.parent && node.parent.parent.type === 'Program') {
if (
node.parent &&
node.parent.type === 'ExportNamedDeclaration' &&
node.parent.parent &&
node.parent.parent.type === 'Program'
) {
// Declaration is a `export const foo = 'asdf'` in root of the module.
return;
}
Expand All @@ -29,15 +33,15 @@ module.exports = {
let nodeText = nodeSourceCode.getText(node);

// Transform the `const` to a `let` declaration
let fixed = nodeText.replace('const', 'let')
let fixed = nodeText.replace('const', 'let');

// // Apply and return the fix
return fixer.replaceText(node, fixed);
}
},
});
}
};
}
},
};
},
};

module.exports.schema = []; // no options
32 changes: 19 additions & 13 deletions lib/rules/no-empty-yuidoc-code-blocks.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
'use strict';

function isDocComment(comment) {
return comment.value[0] === '*';
return comment.value[0] === '*';
}

function hasEmptyCodeBlock(comment) {
return comment.value.match(/(^```(js|javascript|.+\.js\s*)$)(\s)*?(```$)/gm);
return comment.value.match(/(^```(js|javascript|.+\.js\s*)$)(\s)*?(```$)/gm);
}

module.exports = function(context) {
var sourceCode = context.getSourceCode();
module.exports = function (context) {
var sourceCode = context.getSourceCode();

sourceCode.getAllComments().forEach(function(comment) {
if (comment.type !== 'Block') { return; }
if (!isDocComment(comment)) { return; }
if (!hasEmptyCodeBlock(comment)) { return; }
sourceCode.getAllComments().forEach(function (comment) {
if (comment.type !== 'Block') {
return;
}
if (!isDocComment(comment)) {
return;
}
if (!hasEmptyCodeBlock(comment)) {
return;
}

context.report({
loc: comment.loc.start,
message: 'Code blocks cannot be empty inside doc comments.'
});
context.report({
loc: comment.loc.start,
message: 'Code blocks cannot be empty inside doc comments.',
});
});

return {}
return {};
};

module.exports.schema = []; // no options
44 changes: 26 additions & 18 deletions lib/rules/require-yuidoc-access.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
'use strict';

function isDocComment(comment) {
return comment.value[0] === '*';
return comment.value[0] === '*';
}

function isModuleOnlyComment(comment) {
return comment.value.match(/^\*\r?\n\s*@module.+\r?\n(?:\s*@submodule.+\r?\n)?$/);
return comment.value.match(/^\*\r?\n\s*@module.+\r?\n(?:\s*@submodule.+\r?\n)?$/);
}

function includesAccessDeclaration(comment) {
return comment.value.match(/\r?\n\s*(@private|@public|@protected)\s/);
return comment.value.match(/\r?\n\s*(@private|@public|@protected)\s/);
}

module.exports = function(context) {

var sourceCode = context.getSourceCode();

sourceCode.getAllComments().forEach(function(comment) {
if (comment.type !== 'Block') { return; }
if (!isDocComment(comment)) { return; }
if (isModuleOnlyComment(comment)) { return; }
if (includesAccessDeclaration(comment)) { return; }

context.report({
loc: comment.loc.start,
message: 'Access declaration missing, you must supply `@public`, `@private`, or `@protected` for doc comments.'
})
module.exports = function (context) {
var sourceCode = context.getSourceCode();

sourceCode.getAllComments().forEach(function (comment) {
if (comment.type !== 'Block') {
return;
}
if (!isDocComment(comment)) {
return;
}
if (isModuleOnlyComment(comment)) {
return;
}
if (includesAccessDeclaration(comment)) {
return;
}

context.report({
loc: comment.loc.start,
message:
'Access declaration missing, you must supply `@public`, `@private`, or `@protected` for doc comments.',
});
});

return {}
return {};
};

module.exports.schema = []; // no options
59 changes: 32 additions & 27 deletions lib/rules/require-yuidoc-code-block-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@
var lineColumn = require('line-column');

function isDocComment(comment) {
return comment.value[0] === '*';
return comment.value[0] === '*';
}

function getEmptyCodeBlocks(comment) {
var empty = [];
var regex = /(?:```)(\S*)(?:[\s\S]+?)(?:```)/gm;
var match;
var col = lineColumn(comment.value);

while ((match = regex.exec(comment.value)) !== null) {
if (match && match[1] === '') {
var loc = col.fromIndex(match.index);
empty.push({ match: match, loc: loc });
}
var empty = [];
var regex = /(?:```)(\S*)(?:[\s\S]+?)(?:```)/gm;
var match;
var col = lineColumn(comment.value);

while ((match = regex.exec(comment.value)) !== null) {
if (match && match[1] === '') {
var loc = col.fromIndex(match.index);
empty.push({ match: match, loc: loc });
}
return empty;
}
return empty;
}

module.exports = function(context) {
module.exports = function (context) {
var sourceCode = context.getSourceCode();

var sourceCode = context.getSourceCode();

sourceCode.getAllComments().forEach(function(comment) {
if (comment.type !== 'Block') { return; }
if (!isDocComment(comment)) { return; }
var emptyCodeBlocks = getEmptyCodeBlocks(comment);
if (!emptyCodeBlocks || !emptyCodeBlocks.length) { return; }
sourceCode.getAllComments().forEach(function (comment) {
if (comment.type !== 'Block') {
return;
}
if (!isDocComment(comment)) {
return;
}
var emptyCodeBlocks = getEmptyCodeBlocks(comment);
if (!emptyCodeBlocks || !emptyCodeBlocks.length) {
return;
}

emptyCodeBlocks.forEach(function (block) {
context.report({
loc: block.loc,
message: 'Code blocks require a type, like `javascript`, for doc comments.'
});
});
emptyCodeBlocks.forEach(function (block) {
context.report({
loc: block.loc,
message: 'Code blocks require a type, like `javascript`, for doc comments.',
});
});
});

return {};
return {};
};

module.exports.schema = []; // no options
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@
"author": "Tobias Bieniek",
"main": "lib/index.js",
"scripts": {
"lint:fix": "yarn lint --fix",
"lint": "eslint .",
"test": "mocha tests --recursive"
},
"dependencies": {
"line-column": "^1.0.2",
"requireindex": "~1.1.0"
"line-column": "^1.0.2"
},
"devDependencies": {
"eslint": "~2.6.0",
"mocha": "^3.0.2"
"eslint": "~7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"mocha": "^8.1.3",
"prettier": "^2.1.2"
},
"license": "MIT",
"directories": {
"test": "tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Turbo87/eslint-plugin-ember-internal.git"
"url": "git+https://github.com/emberjs/eslint-plugin-ember-internal.git"
},
"bugs": {
"url": "https://github.com/Turbo87/eslint-plugin-ember-internal/issues"
"url": "https://github.com/emberjs/eslint-plugin-ember-internal/issues"
},
"homepage": "https://github.com/Turbo87/eslint-plugin-ember-internal#readme"
"homepage": "https://github.com/emberjs/eslint-plugin-ember-internal#readme"
}
Loading