Addition of eslint-plugin
This commit is contained in:
Родитель
c7a417da41
Коммит
692ad88684
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,7 @@
|
|||
// This is a workaround for https://github.com/eslint/eslint/issues/3458
|
||||
require("@rushstack/eslint-config/patch-eslint6");
|
||||
|
||||
module.exports = {
|
||||
extends: [ "@rushstack/eslint-config" ],
|
||||
parserOptions: { tsconfigRootDir: __dirname },
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
# Ignore everything by default
|
||||
**
|
||||
|
||||
# Use negative patterns to bring back the specific things we want to publish
|
||||
!/bin/**
|
||||
!/lib/**
|
||||
!/dist/**
|
||||
!ThirdPartyNotice.txt
|
||||
|
||||
# Ignore certain files in the above folder
|
||||
/dist/*.stats.*
|
||||
/lib/**/test/*
|
||||
/lib/**/__tests__/*
|
||||
|
||||
# NOTE: These don't need to be specified, because NPM includes them automatically.
|
||||
#
|
||||
# package.json
|
||||
# README (and its variants)
|
||||
# CHANGELOG (and its variants)
|
||||
# LICENSE / LICENCE
|
||||
|
||||
## Project specific definitions
|
||||
# -----------------------------
|
||||
|
||||
# (Add your exceptions here)
|
|
@ -0,0 +1,2 @@
|
|||
registry=https://registry.npmjs.org/
|
||||
always-auth=false
|
|
@ -0,0 +1,22 @@
|
|||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const child_process = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const production = process.argv.indexOf('--production') >= 0;
|
||||
const baseDir = __dirname;
|
||||
|
||||
process.chdir(baseDir);
|
||||
|
||||
process.exitCode = 1;
|
||||
try {
|
||||
child_process.execSync(path.join(baseDir, 'node_modules/.bin/rimraf')
|
||||
+ ' ./lib/', { stdio: 'inherit' });
|
||||
|
||||
console.log('-- TYPESCRIPT --\n');
|
||||
child_process.execSync(path.join(baseDir, 'node_modules/.bin/tsc'), { stdio: 'inherit' });
|
||||
|
||||
console.log('-- ESLINT --\n');
|
||||
child_process.execSync(path.join(baseDir, 'node_modules/.bin/eslint')
|
||||
+ ' -f unix \"src/**/*.{ts,tsx}\"',
|
||||
{ stdio: 'inherit' });
|
||||
|
||||
if (production) {
|
||||
console.log('-- TEST --\n');
|
||||
|
||||
require('./lib/tests/index.js');
|
||||
}
|
||||
|
||||
process.exitCode = 0;
|
||||
} catch (e) {
|
||||
console.log('ERROR: ' + e.message);
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "eslint-plugin-tsdoc",
|
||||
"version": "0.1.0",
|
||||
"description": "eslint plugin for tsdoc",
|
||||
"private": false,
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "node ./build.js",
|
||||
"lint": "eslint -f unix \"src/**/*.{ts,tsx}\"",
|
||||
"test": "node lib/tests/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/tsdoc": "0.12.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rushstack/eslint-config": "0.4.0",
|
||||
"@types/eslint": "6.1.3",
|
||||
"@types/node": "10.7.1",
|
||||
"eslint": "^6.0.0",
|
||||
"typescript": "~3.5.3"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
import { ParserMessageLog, TSDocParser } from "@microsoft/tsdoc";
|
||||
import { allTsdocMessageIds } from "@microsoft/tsdoc/lib/parser/TSDocMessageId";
|
||||
import * as eslint from "eslint";
|
||||
import * as ESTree from "estree";
|
||||
|
||||
const messageIds: {[x: string]: string} = {};
|
||||
|
||||
allTsdocMessageIds.forEach((messageId: string) => {
|
||||
messageIds[messageId] = `${messageId}: {{ unformattedText }}`;
|
||||
});
|
||||
|
||||
interface IPlugin {
|
||||
rules: {[x: string]: eslint.Rule.RuleModule};
|
||||
}
|
||||
|
||||
export const plugin: IPlugin = {
|
||||
rules: {
|
||||
"tsdoc-comments": {
|
||||
meta: {
|
||||
messages: messageIds,
|
||||
type: "problem",
|
||||
docs: {
|
||||
description: "Validates tsdoc comments",
|
||||
category: "Typescript",
|
||||
recommended: false,
|
||||
url: "https://github.com/microsoft/tsdoc"
|
||||
}
|
||||
},
|
||||
create: (context: eslint.Rule.RuleContext) => {
|
||||
const tsDocParser: TSDocParser = new TSDocParser();
|
||||
const sourceCode: eslint.SourceCode = context.getSourceCode();
|
||||
const checkCommentBlocks: (node: ESTree.Node) => void = function (node: ESTree.Node) {
|
||||
const commentBlocks: ESTree.Comment[] = sourceCode.getCommentsBefore(node).filter(function (comment: ESTree.Comment) {
|
||||
return comment.type === "Block";
|
||||
});
|
||||
if (commentBlocks.length > 0) {
|
||||
const commentBlock: ESTree.Comment = commentBlocks[0];
|
||||
const commentString: string = "/*" + commentBlock.value + "*/";
|
||||
const results: ParserMessageLog = tsDocParser.parseString(commentString).log;
|
||||
for (const message of results.messages) {
|
||||
context.report({
|
||||
node: node,
|
||||
messageId: message.messageId,
|
||||
data: {
|
||||
unformattedText: message.unformattedText
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ClassDeclaration: checkCommentBlocks,
|
||||
FunctionDeclaration: checkCommentBlocks
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
import { RuleTester } from "eslint";
|
||||
import { plugin } from "../index";
|
||||
|
||||
const ruleTester: RuleTester = new RuleTester({
|
||||
env: {
|
||||
es6: true
|
||||
}
|
||||
});
|
||||
ruleTester.run("tsdoc-comments", plugin.rules["tsdoc-comments"], {
|
||||
valid: [
|
||||
"/**\nA great function!\n */\nfunction foobar() {}\n",
|
||||
"/**\nA great class!\n */\nclass FooBar {}\n"
|
||||
],
|
||||
invalid: [{
|
||||
code: "/**\n * This `is wrong\n */\nfunction foobar() {}\n",
|
||||
errors: [{
|
||||
messageId: "tsdoc-code-span-missing-delimiter"
|
||||
}]
|
||||
}, {
|
||||
code: "/**\n * This `is wrong\n */\nclass FooBar {}\n",
|
||||
errors: [{
|
||||
messageId: "tsdoc-code-span-missing-delimiter"
|
||||
}]
|
||||
}]
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/tsconfig",
|
||||
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"sourceMap": false,
|
||||
"experimentalDecorators": true,
|
||||
"types": [
|
||||
"eslint",
|
||||
"node"
|
||||
],
|
||||
|
||||
"lib": [
|
||||
"es5",
|
||||
"scripthost",
|
||||
"es2015.collection",
|
||||
"es2015.promise",
|
||||
"es2015.iterable"
|
||||
],
|
||||
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"strictPropertyInitialization": true,
|
||||
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
"dependencies": {
|
||||
"@microsoft/tsdoc": "0.12.14",
|
||||
"@types/react": "16.9.6",
|
||||
"@types/react-dom": "16.9.2",
|
||||
"@types/react-dom": "16.9.3",
|
||||
"promise": "~8.0.3",
|
||||
"monaco-editor": "~0.17.1",
|
||||
"tslib": "~1.10.0"
|
||||
|
|
|
@ -372,6 +372,10 @@
|
|||
"packageName": "@microsoft/tsdoc",
|
||||
"projectFolder": "tsdoc",
|
||||
"shouldPublish": true
|
||||
},
|
||||
{
|
||||
"packageName": "eslint-plugin-tsdoc",
|
||||
"projectFolder": "eslint-plugin"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче