Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zhlint

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zhlint - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

lib/hypers/hexo.d.ts

14

bin/index.js

@@ -6,2 +6,3 @@ #!/usr/bin/env node

const glob = require('glob')
const gitignore = require('ignore')
const { readRc, runWithConfig, report } = require('../')

@@ -28,3 +29,7 @@

--ignore <filepath>
--file-ignore <filepath>
.zhlintignore by default
--case-ignore <filepath>
.zhlintcaseignore by default

@@ -74,7 +79,10 @@ --dir <path>

const configPath = argv.config
const ignorePath = argv.ignore
const config = readRc(configDir, configPath, ignorePath)
const fileIgnorePath = argv.ignore || argv['file-ignore']
const caseIgnorePath = argv['case-ignore']
const config = readRc(configDir, configPath, fileIgnorePath, caseIgnorePath)
const fileIgnore = gitignore().add(config.fileIgnores)
const fileIgnoreFilter = fileIgnore.createFilter()
try {
const files = glob.sync(filePattern)
const resultList = files.map((file) => {
const resultList = files.filter(fileIgnoreFilter).map((file) => {
console.log(`[start] ${file}`)

@@ -81,0 +89,0 @@ const origin = fs.readFileSync(file, { encoding: 'utf8' })

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runWithConfig = exports.readRc = exports.report = exports.run = void 0;
const run_1 = require("./run");
exports.readRc = exports.report = exports.runWithConfig = exports.run = void 0;
var run_1 = require("./run");
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } });
Object.defineProperty(exports, "runWithConfig", { enumerable: true, get: function () { return run_1.runWithConfig; } });
const report_1 = require("./report");
var report_1 = require("./report");
Object.defineProperty(exports, "report", { enumerable: true, get: function () { return report_1.report; } });
const rc_1 = require("./rc");
var rc_1 = require("./rc");
Object.defineProperty(exports, "readRc", { enumerable: true, get: function () { return rc_1.readRc; } });
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -138,4 +142,4 @@ if (k2 === undefined) k2 = k;

// ignored cases
if (config.ignores) {
config.ignores.forEach((x) => {
if (config.caseIgnores) {
config.caseIgnores.forEach((x) => {
const ignoredCase = (0, ignore_1.parseIngoredCase)(x);

@@ -142,0 +146,0 @@ if (ignoredCase) {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QUOTE_NOT_OPEN = exports.QUOTE_NOT_CLOSED = exports.BRACKET_NOT_OPEN = exports.BRACKET_NOT_CLOSED = void 0;
exports.QUOTATION_NOT_OPEN = exports.QUOTATION_NOT_CLOSED = exports.BRACKET_NOT_OPEN = exports.BRACKET_NOT_CLOSED = void 0;
exports.BRACKET_NOT_CLOSED = '括号未闭合';
exports.BRACKET_NOT_OPEN = '括号未匹配';
exports.QUOTE_NOT_CLOSED = '引号未闭合';
exports.QUOTE_NOT_OPEN = '引号未匹配';
exports.QUOTATION_NOT_CLOSED = '引号未闭合';
exports.QUOTATION_NOT_OPEN = '引号未匹配';

@@ -45,3 +45,3 @@ "use strict";

CharType["UNKNOWN"] = "unknown";
})(CharType = exports.CharType || (exports.CharType = {}));
})(CharType || (exports.CharType = CharType = {}));
exports.BRACKET_CHAR_SET = {

@@ -86,3 +86,3 @@ left: '([{(〔[{',

MarkType["RAW"] = "raw";
})(MarkType = exports.MarkType || (exports.MarkType = {}));
})(MarkType || (exports.MarkType = MarkType = {}));
var MarkSideType;

@@ -92,3 +92,3 @@ (function (MarkSideType) {

MarkSideType["RIGHT"] = "right";
})(MarkSideType = exports.MarkSideType || (exports.MarkSideType = {}));
})(MarkSideType || (exports.MarkSideType = MarkSideType = {}));
const isRawMark = (mark) => {

@@ -129,7 +129,7 @@ return mark.code !== undefined;

HyperTokenType["INDETERMINATED"] = "indeterminated";
})(HyperTokenType = exports.HyperTokenType || (exports.HyperTokenType = {}));
})(HyperTokenType || (exports.HyperTokenType = HyperTokenType = {}));
var GroupTokenType;
(function (GroupTokenType) {
GroupTokenType["GROUP"] = "group";
})(GroupTokenType = exports.GroupTokenType || (exports.GroupTokenType = {}));
})(GroupTokenType || (exports.GroupTokenType = GroupTokenType = {}));
const getHalfwidthTokenType = (type) => {

@@ -136,0 +136,0 @@ switch (type) {

@@ -58,3 +58,3 @@ "use strict";

addUnmatchedToken(status, i, char);
addError(status, i, messages_1.QUOTE_NOT_OPEN);
addError(status, i, messages_1.QUOTATION_NOT_OPEN);
}

@@ -148,3 +148,3 @@ else {

value: value,
spaceAfter: '',
spaceAfter: '', // to be finalized
mark: mark,

@@ -177,3 +177,3 @@ markSide

startValue: char,
endIndex: -1,
endIndex: -1, // to be finalized
endValue: '' // to be finalized

@@ -191,3 +191,3 @@ };

value: char,
spaceAfter: '',
spaceAfter: '', // to be finalized
mark: status.lastMark,

@@ -241,7 +241,7 @@ markSide

index,
spaceAfter: '',
spaceAfter: '', // to be finalized
startIndex: index,
startValue: char,
endIndex: -1,
endValue: '',
endIndex: -1, // to be finalized
endValue: '', // to be finalized
innerSpaceBefore: '' // to be finalized

@@ -274,4 +274,4 @@ });

index,
length: 1,
value: char,
length: 1, // to be finalized
value: char, // to be finalized
spaceAfter: '' // to be finalized

@@ -333,2 +333,5 @@ };

}
if (str.length <= index + 1) {
return false;
}
const nextChar = str[index + 1];

@@ -391,3 +394,3 @@ const nextType = (0, char_1.checkCharType)(nextChar);

if (lastGroup && lastGroup.startValue && !lastGroup.endValue) {
addError(status, lastGroup.startIndex, messages_1.QUOTE_NOT_CLOSED);
addError(status, lastGroup.startIndex, messages_1.QUOTATION_NOT_CLOSED);
}

@@ -398,3 +401,3 @@ // record an error if `groupStack` not fully resolved

if (group !== lastGroup && group.startValue && !group.endValue) {
addError(status, group.startIndex, messages_1.QUOTE_NOT_CLOSED);
addError(status, group.startIndex, messages_1.QUOTATION_NOT_CLOSED);
}

@@ -401,0 +404,0 @@ });

@@ -7,6 +7,10 @@ "use strict";

const report_1 = require("../report");
const resolvePath = (dir, config, ignore, logger = report_1.env.defaultLogger) => {
const DEFAULT_CONFIG_PATH = '.zhlintrc';
const DEFAULT_FILE_IGNORE_PATH = '.zhlintignore';
const DEFAULT_CASE_IGNORE_PATH = '.zhlintcaseignore';
const resolvePath = (dir, config, fileIgnore, caseIgnore, logger = report_1.env.defaultLogger) => {
const result = {
config: undefined,
ignore: undefined
fileIgnore: undefined,
caseIgnore: undefined,
};

@@ -18,3 +22,3 @@ dir = (0, path_1.resolve)(dir !== null && dir !== void 0 ? dir : '.');

}
config = (0, path_1.resolve)(dir, config !== null && config !== void 0 ? config : '.zhlintrc');
config = (0, path_1.resolve)(dir, config !== null && config !== void 0 ? config : DEFAULT_CONFIG_PATH);
if ((0, fs_1.existsSync)(config)) {

@@ -26,9 +30,16 @@ result.config = config;

}
ignore = (0, path_1.resolve)(dir, ignore !== null && ignore !== void 0 ? ignore : '.zhlintignore');
if ((0, fs_1.existsSync)(ignore)) {
result.ignore = ignore;
fileIgnore = (0, path_1.resolve)(dir, fileIgnore !== null && fileIgnore !== void 0 ? fileIgnore : DEFAULT_FILE_IGNORE_PATH);
if ((0, fs_1.existsSync)(fileIgnore)) {
result.fileIgnore = fileIgnore;
}
else {
logger.log(`Global ignored cases file "${ignore}" does not exist. Will proceed as none.`);
logger.log(`Global ignored cases file "${fileIgnore}" does not exist. Will proceed as none.`);
}
caseIgnore = (0, path_1.resolve)(dir, caseIgnore !== null && caseIgnore !== void 0 ? caseIgnore : DEFAULT_CASE_IGNORE_PATH);
if ((0, fs_1.existsSync)(caseIgnore)) {
result.caseIgnore = caseIgnore;
}
else {
logger.log(`Global ignored cases file "${caseIgnore}" does not exist. Will proceed as none.`);
}
return result;

@@ -41,3 +52,3 @@ };

};
const resolveConfig = (normalizedConfigPath, normalizedIgnorePath, logger = report_1.env.defaultLogger) => {
const resolveConfig = (normalizedConfigPath, normalizedFileIgnorePath, normalizedCaseIgnorePath, logger = report_1.env.defaultLogger) => {
const result = {

@@ -58,5 +69,8 @@ preset: 'default'

}
if (Array.isArray(config.ignores)) {
result.ignores = config.ignores;
if (Array.isArray(config.fileIgnores)) {
result.fileIgnores = config.fileIgnores;
}
if (Array.isArray(config.caseIgnores)) {
result.caseIgnores = config.caseIgnores;
}
}

@@ -67,6 +81,6 @@ catch (error) {

}
if (normalizedIgnorePath) {
if (normalizedFileIgnorePath) {
try {
const ignores = (0, fs_1.readFileSync)(normalizedIgnorePath, { encoding: 'utf8' });
ignores
const fileIgnores = (0, fs_1.readFileSync)(normalizedFileIgnorePath, { encoding: 'utf8' });
fileIgnores
.split(/\n/)

@@ -78,7 +92,7 @@ .map((x) => x.trim())

}
if (!result.ignores) {
result.ignores = [];
if (!result.fileIgnores) {
result.fileIgnores = [];
}
if (result.ignores.indexOf(x) === -1) {
result.ignores.push(x);
if (result.fileIgnores.indexOf(x) === -1) {
result.fileIgnores.push(x);
}

@@ -88,11 +102,33 @@ });

catch (error) {
logger.log(`Failed to read "${normalizedIgnorePath}": ${error.message}`);
logger.log(`Failed to read "${normalizedFileIgnorePath}": ${error.message}`);
}
}
if (normalizedCaseIgnorePath) {
try {
const caseIgnores = (0, fs_1.readFileSync)(normalizedCaseIgnorePath, { encoding: 'utf8' });
caseIgnores
.split(/\n/)
.map((x) => x.trim())
.forEach((x) => {
if (!x) {
return;
}
if (!result.caseIgnores) {
result.caseIgnores = [];
}
if (result.caseIgnores.indexOf(x) === -1) {
result.caseIgnores.push(x);
}
});
}
catch (error) {
logger.log(`Failed to read "${normalizedCaseIgnorePath}": ${error.message}`);
}
}
return result;
};
const readRc = (dir, config, ignore, logger = report_1.env.defaultLogger) => {
const { config: normalizedConfigPath, ignore: normalizedIgnorePath } = resolvePath(dir, config, ignore, logger);
return resolveConfig(normalizedConfigPath, normalizedIgnorePath, logger);
const readRc = (dir, config, fileIgnore, caseIgnore, logger = report_1.env.defaultLogger) => {
const { config: normalizedConfigPath, fileIgnore: normalizedFileIgnorePath, caseIgnore: normalizedCaseIgnorePath } = resolvePath(dir, config, fileIgnore, caseIgnore, logger);
return resolveConfig(normalizedConfigPath, normalizedFileIgnorePath, normalizedCaseIgnorePath, logger);
};
exports.readRc = readRc;

@@ -48,3 +48,3 @@ "use strict";

ValidationTarget["INNER_SPACE_BEFORE"] = "innerSpaceBefore";
})(ValidationTarget = exports.ValidationTarget || (exports.ValidationTarget = {}));
})(ValidationTarget || (exports.ValidationTarget = ValidationTarget = {}));
const adjustedFullwidthPunctuations = `“”‘’`;

@@ -51,0 +51,0 @@ const generateMarker = (str, index) => {

@@ -20,2 +20,3 @@ "use strict";

const case_html_entity_1 = __importDefault(require("./case-html-entity"));
const case_pure_western_1 = __importDefault(require("./case-pure-western"));
const generateHandlers = (options) => {

@@ -35,3 +36,4 @@ return [

(0, case_zh_units_1.default)(options),
(0, case_html_entity_1.default)(options)
(0, case_html_entity_1.default)(options),
(0, case_pure_western_1.default)(options),
];

@@ -72,4 +74,5 @@ };

'a.k.a.'
]
],
skipPureWestern: true,
};
exports.default = generateHandlers;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TRIM_SPACE = exports.QUOTE_SPACE_OUTSIDE = exports.QUOTE_NOSPACE_OUTSIDE = exports.QUOTE_NOSPACE_INSIDE = exports.CONTENT_NOSPACE_MIXED_WIDTH = exports.CONTENT_SPACE_MIXED_WIDTH = exports.CONTENT_NOSPACE_FULL_WIDTH = exports.CONTENT_SPACE_HALF_WIDTH = exports.BRACKET_SPACE_OUTSIDE = exports.BRACKET_NOSPACE_OUTSIDE = exports.BRACKET_NOSPACE_INSIDE = exports.PUNCTUATION_SPACE_AFTER = exports.PUNCTUATION_NOSPACE_AFTER = exports.PUNCTUATION_NOSPACE_BEFORE = exports.PUNCTUATION_HALF_WIDTH = exports.PUNCTUATION_FULL_WIDTH = exports.PUNCTUATION_UNIFICATION_SIMPLIFIED = exports.PUNCTUATION_UNIFICATION_TRADITIONAL = exports.PUNCTUATION_UNIFICATION = exports.MARKDOWN_NOSPACE_INSIDE = exports.MARKDOWN_SPACE_OUTSIDE = exports.CODE_NOSPACE_OUTSIDE = exports.CODE_SPACE_OUTSIDE = void 0;
exports.TRIM_SPACE = exports.QUOTATION_SPACE_OUTSIDE = exports.QUOTATION_NOSPACE_OUTSIDE = exports.QUOTATION_NOSPACE_INSIDE = exports.CONTENT_NOSPACE_MIXED_WIDTH = exports.CONTENT_SPACE_MIXED_WIDTH = exports.CONTENT_NOSPACE_FULL_WIDTH = exports.CONTENT_SPACE_HALF_WIDTH = exports.BRACKET_SPACE_OUTSIDE = exports.BRACKET_NOSPACE_OUTSIDE = exports.BRACKET_NOSPACE_INSIDE = exports.PUNCTUATION_SPACE_AFTER = exports.PUNCTUATION_NOSPACE_AFTER = exports.PUNCTUATION_NOSPACE_BEFORE = exports.PUNCTUATION_HALF_WIDTH = exports.PUNCTUATION_FULL_WIDTH = exports.PUNCTUATION_UNIFICATION_SIMPLIFIED = exports.PUNCTUATION_UNIFICATION_TRADITIONAL = exports.PUNCTUATION_UNIFICATION = exports.MARKDOWN_NOSPACE_INSIDE = exports.MARKDOWN_SPACE_OUTSIDE = exports.CODE_NOSPACE_OUTSIDE = exports.CODE_SPACE_OUTSIDE = void 0;
exports.CODE_SPACE_OUTSIDE = '此处内联代码的外部需要一个空格';

@@ -23,5 +23,5 @@ exports.CODE_NOSPACE_OUTSIDE = '此处内联代码的外部不需要空格';

exports.CONTENT_NOSPACE_MIXED_WIDTH = '此处中英文内容之间需要一个空格';
exports.QUOTE_NOSPACE_INSIDE = '此处引号的内部不需要空格';
exports.QUOTE_NOSPACE_OUTSIDE = '此处引号的外部不需要空格';
exports.QUOTE_SPACE_OUTSIDE = '此处引号的外部需要一个空格';
exports.QUOTATION_NOSPACE_INSIDE = '此处引号的内部不需要空格';
exports.QUOTATION_NOSPACE_OUTSIDE = '此处引号的外部不需要空格';
exports.QUOTATION_SPACE_OUTSIDE = '此处引号的外部需要一个空格';
exports.TRIM_SPACE = '此处需要去除外部空格';

@@ -18,8 +18,8 @@ "use strict";

* - right-half-bracket x left-half-bracket
* - right-half-bracket x content/left-quote/code
* - content/right-quote/code x left-half-bracket
* - right-half-bracket x content/left-quotation/code
* - content/right-quotation/code x left-half-bracket
* - noSpaceOutsideFullBracket:
* - right-full-bracket x left-full-bracket
* - right-full-bracket x content/left-quote/code
* - content/right-quote/code x left-full-bracket
* - right-full-bracket x content/left-quotation/code
* - content/right-quotation/code x left-full-bracket
*/

@@ -130,4 +130,4 @@ Object.defineProperty(exports, "__esModule", { value: true });

}
// 2.2 content/right-quote/code x left-bracket
// 2.3 right-racket x content/left-quote/code
// 2.2 content/right-quotation/code x left-bracket
// 2.3 right-racket x content/left-quotation/code
if (token.markSide === parser_1.MarkSideType.LEFT) {

@@ -139,4 +139,4 @@ if (contentTokenBefore &&

if (beforeSpaceHost) {
// 2.2.1 content/right-quote/code x left-full-bracket
// 2.2.2 content/right-quote/code x left-half-bracket
// 2.2.1 content/right-quotation/code x left-full-bracket
// 2.2.2 content/right-quotation/code x left-half-bracket
if (fullWidth ||

@@ -167,4 +167,4 @@ (contentTokenBefore.type === parser_1.GroupTokenType.GROUP &&

if (afterSpaceHost) {
// 2.3.1 right-full-bracket x content/left-quote/code
// 2.4.2 right-half-bracket x content/left-quote/code
// 2.3.1 right-full-bracket x content/left-quotation/code
// 2.4.2 right-half-bracket x content/left-quotation/code
if (fullWidth ||

@@ -171,0 +171,0 @@ (contentTokenAfter.type === parser_1.GroupTokenType.GROUP &&

@@ -22,7 +22,7 @@ "use strict";

* - noSpaceBeforePunctuation:
* content/right-quote/right-bracket/code x punctuation
* content/right-quotation/right-bracket/code x punctuation
* - spaceAfterHalfWidthPunctuation:
* half x content/left-quote/left-bracket/code
* half x content/left-quotation/left-bracket/code
* - noSpaceAfterFullWidthPunctuation:
* full x content/left-quote/left-bracket/code
* full x content/left-quotation/left-bracket/code
*

@@ -29,0 +29,0 @@ * - skip half-width punctuations between half-width content without space

@@ -8,19 +8,19 @@ "use strict";

* Options
* - noSpaceInsideQuote: boolean | undefined
* - spaceOutsideHalfQuote: boolean | undefined
* - noSpaceOutsideFullQuote: boolean | undefined
* - noSpaceInsideQuotation: boolean | undefined
* - spaceOutsideHalfwidthQuotation: boolean | undefined
* - noSpaceOutsideFullwidthQuotation: boolean | undefined
*
* Details:
* - noSpaceInsideQuote:
* - left-quote x right-quote
* - content/punctuation/right-quote/right-bracket/code/unknown/container x right-quote
* - left-quote x content/punctuation/left-quote/left-bracket/code/unknown/container
* - spaceOutsideHalfQuote:
* - right-half-quote x left-half-quote
* - content/code x left-half-quote
* - right-half-quote x content/code
* - noSpaceOutsideFullQuote:
* - right-full-quote x left-full-quote
* - content/code x left-full-quote
* - right-full-quote x content/code
* - noSpaceInsideQuotation:
* - left-quotation x right-quotation
* - content/punctuation/right-quotation/right-bracket/code/unknown/container x right-quotation
* - left-quotation x content/punctuation/left-quotation/left-bracket/code/unknown/container
* - spaceOutsideHalfwidthQuotation:
* - right-half-quotation x left-half-quotation
* - content/code x left-half-quotation
* - right-half-quotation x content/code
* - noSpaceOutsideFullwidthQuotation:
* - right-full-quotation x left-full-quotation
* - content/code x left-full-quotation
* - right-full-quotation x content/code
*/

@@ -36,5 +36,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

const generateHandler = (options) => {
const noSpaceInsideQuoteOption = options.noSpaceInsideQuotation;
const spaceOutsideHalfQuoteOption = options.spaceOutsideHalfwidthQuotation;
const noSpaceOutsideFullQuoteOption = options.noSpaceOutsideFullwidthQuotation;
const noSpaceInsideQuotationOption = options.noSpaceInsideQuotation;
const spaceOutsideHalfQuotationOption = options.spaceOutsideHalfwidthQuotation;
const noSpaceOutsideFullQuotationOption = options.noSpaceOutsideFullwidthQuotation;
const adjustedFullWidthOption = options.adjustedFullwidthPunctuation || '';

@@ -47,23 +47,23 @@ return (token, _, group) => {

// 1. no space inside quotation
if (noSpaceInsideQuoteOption) {
// 1.1 left-quote x content/punctuation/left-quote/left-bracket/code/unknown/container
if (noSpaceInsideQuotationOption) {
// 1.1 left-quotation x content/punctuation/left-quotation/left-bracket/code/unknown/container
const firstInsdieToken = token[0];
if (firstInsdieToken &&
firstInsdieToken.markSide !== parser_1.MarkSideType.RIGHT) {
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTE_NOSPACE_INSIDE);
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTATION_NOSPACE_INSIDE);
}
// 1.2 content/punctuation/right-quote/right-bracket/code/unknown/container x right-quote
// 1.2 content/punctuation/right-quotation/right-bracket/code/unknown/container x right-quotation
const lastInsideToken = token[token.length - 1];
if (lastInsideToken && lastInsideToken.markSide !== parser_1.MarkSideType.LEFT) {
(0, util_1.checkSpaceAfter)(lastInsideToken, '', messages_1.QUOTE_NOSPACE_INSIDE);
(0, util_1.checkSpaceAfter)(lastInsideToken, '', messages_1.QUOTATION_NOSPACE_INSIDE);
}
// 1.3 left-quote x right-quote
// 1.3 left-quotation x right-quotation
if (!firstInsdieToken) {
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTE_NOSPACE_INSIDE);
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTATION_NOSPACE_INSIDE);
}
}
// 2. space outside half/full quotation
if (typeof spaceOutsideHalfQuoteOption !== 'undefined' ||
noSpaceOutsideFullQuoteOption) {
// 2.1 right-quote x left-quote
if (typeof spaceOutsideHalfQuotationOption !== 'undefined' ||
noSpaceOutsideFullQuotationOption) {
// 2.1 right-quotation x left-quotation
const contentTokenAfter = (0, util_1.findNonCodeVisibleTokenAfter)(group, token);

@@ -76,15 +76,15 @@ if (contentTokenAfter &&

isFullWidth(contentTokenAfter.modifiedStartValue, adjustedFullWidthOption);
// 2.1.1 right-full-quote x left-full-quote
// 2.1.2 right-half-quote x left-half-quote
// 2.1.1 right-full-quotation x left-full-quotation
// 2.1.2 right-half-quotation x left-half-quotation
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_SPACE_OUTSIDE);
if (noSpaceOutsideFullQuotationOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_SPACE_OUTSIDE);
}
}
else {
if (typeof spaceOutsideHalfQuoteOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuoteOption ? ' ' : '';
const message = spaceOutsideHalfQuoteOption
? messages_1.QUOTE_SPACE_OUTSIDE
: messages_1.QUOTE_NOSPACE_OUTSIDE;
if (typeof spaceOutsideHalfQuotationOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuotationOption ? ' ' : '';
const message = spaceOutsideHalfQuotationOption
? messages_1.QUOTATION_SPACE_OUTSIDE
: messages_1.QUOTATION_NOSPACE_OUTSIDE;
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message);

@@ -95,3 +95,3 @@ }

}
// 2.2 content/code x left-quote
// 2.2 content/code x left-quotation
const contentTokenBefore = (0, util_1.findNonCodeVisibleTokenBefore)(group, token);

@@ -104,15 +104,15 @@ if (contentTokenBefore &&

const fullWidth = isFullWidth(token.modifiedStartValue, adjustedFullWidthOption);
// 2.2.1 content/code x left-full-quote
// 2.2.2 content/code x left-half-quote
// 2.2.1 content/code x left-full-quotation
// 2.2.2 content/code x left-half-quotation
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_NOSPACE_OUTSIDE);
if (noSpaceOutsideFullQuotationOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_NOSPACE_OUTSIDE);
}
}
else {
if (typeof spaceOutsideHalfQuoteOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuoteOption ? ' ' : '';
const message = spaceOutsideHalfQuoteOption
? messages_1.QUOTE_SPACE_OUTSIDE
: messages_1.QUOTE_NOSPACE_OUTSIDE;
if (typeof spaceOutsideHalfQuotationOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuotationOption ? ' ' : '';
const message = spaceOutsideHalfQuotationOption
? messages_1.QUOTATION_SPACE_OUTSIDE
: messages_1.QUOTATION_NOSPACE_OUTSIDE;
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message);

@@ -123,3 +123,3 @@ }

}
// 2.3 right-quote x content/code
// 2.3 right-quotation x content/code
if (contentTokenAfter &&

@@ -131,15 +131,15 @@ ((0, parser_1.isLetterType)(contentTokenAfter.type) ||

const fullWidth = isFullWidth(token.modifiedEndValue, adjustedFullWidthOption);
// 2.3.1 right-full-quote x content/code
// 2.3.2 right-half-quote x content/code
// 2.3.1 right-full-quotation x content/code
// 2.3.2 right-half-quotation x content/code
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_NOSPACE_OUTSIDE);
if (noSpaceOutsideFullQuotationOption) {
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_NOSPACE_OUTSIDE);
}
}
else {
if (typeof spaceOutsideHalfQuoteOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuoteOption ? ' ' : '';
const message = spaceOutsideHalfQuoteOption
? messages_1.QUOTE_SPACE_OUTSIDE
: messages_1.QUOTE_NOSPACE_OUTSIDE;
if (typeof spaceOutsideHalfQuotationOption !== 'undefined') {
const spaceAfter = spaceOutsideHalfQuotationOption ? ' ' : '';
const message = spaceOutsideHalfQuotationOption
? messages_1.QUOTATION_SPACE_OUTSIDE
: messages_1.QUOTATION_NOSPACE_OUTSIDE;
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message);

@@ -154,6 +154,6 @@ }

exports.defaultConfig = {
spaceOutsideHalfQuote: true,
noSpaceInsideQuote: true,
noSpaceOutsideFullQuote: true
spaceOutsideHalfwidthQuotation: true,
noSpaceInsideQuotation: true,
noSpaceOutsideFullwidthQuotation: true
};
exports.default = generateHandler;
{
"name": "zhlint",
"version": "0.7.3",
"version": "0.7.4",
"description": "A linting tool for Chinese language.",

@@ -11,3 +11,3 @@ "bin": {

"jsdelivr": "./dist/zhlint.umd.js",
"types": "./dist/zhlint.d.ts",
"types": "./lib/index.d.ts",
"files": [

@@ -24,3 +24,3 @@ "tsconfig.json",

"type": "git",
"url": "git+https://github.com/Jinjiang/zhlint.git"
"url": "git+https://github.com/zhlint-project/zhlint.git"
},

@@ -35,36 +35,32 @@ "keywords": [

"bugs": {
"url": "https://github.com/Jinjiang/zhlint/issues"
"url": "https://github.com/zhlint-project/zhlint/issues"
},
"homepage": "https://github.com/Jinjiang/zhlint#readme",
"homepage": "https://github.com/zhlint-project/zhlint#readme",
"devDependencies": {
"@algolia/client-search": "^4.12.0",
"@microsoft/api-extractor": "^7.19.4",
"@types/mdast": "^3.0.10",
"@types/node": "^17.0.8",
"@types/react": "^17.0.38",
"@types/unist": "^2.0.6",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"@vitest/ui": "^0.21.1",
"c8": "^7.12.0",
"eslint": "^8.6.0",
"mdast-util-to-markdown": "^1.3.0",
"prettier": "^2.5.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^4.5.4",
"vite": "^2.7.10",
"vite-plugin-node-stdlib-browser": "^0.1.1",
"vitepress": "1.0.0-alpha.4"
"@types/mdast": "^3.0.15",
"@types/node": "^20.11.5",
"@types/react": "^17.0.75",
"@types/unist": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@vitest/ui": "^1.2.1",
"eslint": "^8.56.0",
"mdast-util-to-markdown": "^1.5.0",
"node-stdlib-browser": "^1.2.0",
"prettier": "^3.2.4",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite-plugin-node-polyfills": "^0.19.0",
"vitepress": "1.0.0-rc.39"
},
"dependencies": {
"chalk": "^4.0.0",
"glob": "^7.1.6",
"minimist": "^1.2.0",
"node-stdlib-browser": "^1.2.0",
"remark-frontmatter": "^1.3.2",
"glob": "^10.3.10",
"ignore": "^5.3.0",
"minimist": "^1.2.8",
"remark-frontmatter": "^1.3.3",
"remark-parse": "^7.0.2",
"unified": "^8.4.2",
"vitest": "^0.21.1",
"vue": "^3.4.3"
"vitest": "^1.2.1",
"vue": "^3.4.15"
},

@@ -74,11 +70,9 @@ "scripts": {

"dev:ui": "vitest --ui",
"build": "pnpm run build:js && pnpm run build:type",
"build:js": "pnpm run build:node && pnpm run build:browser",
"build": "pnpm run build:node && pnpm run build:browser",
"build:node": "tsc --project tsconfig-build.json",
"build:browser": "vite build",
"build:type": "api-extractor run --local --verbose",
"lint": "prettier --check .",
"lint:fix": "prettier --write .",
"lint:eslint": "eslint {src,test,types}/**.ts",
"lint:eslint:fix": "eslint {src,test,types}/**.ts --fix",
"lint": "prettier --cache --check .",
"lint:fix": "prettier --cache --write .",
"lint:eslint": "eslint {src,test}/**.ts --cache",
"lint:eslint:fix": "eslint {src,test}/**.ts --cache --fix",
"test": "pnpm run test:tsc && pnpm run test:vitest",

@@ -89,2 +83,3 @@ "test:tsc": "tsc --noEmit",

"docs": "vitepress dev docs",
"docs:runtime": "cp dist/zhlint.es.js* docs/",
"docs:readme": "node scripts/gen-readme.mjs",

@@ -91,0 +86,0 @@ "docs:build": "vitepress build docs",

@@ -53,3 +53,7 @@ # ![logo](docs/logo.svg) zhlint

zhlint --ignore <filepath>
zhlint --file-ignore <filepath>
# .zhlintcaseignore by default
zhlint --case-ignore <filepath>
# current directory by default

@@ -59,3 +63,3 @@ zhlint --dir <path>

In the config file, you can write a JSON like:
In the rc config file, you can write a JSON like:

@@ -66,3 +70,3 @@ ```json

"rules": {
"adjustedFullWidthPunctuation": ""
"adjustedFullwidthPunctuation": ""
}

@@ -74,4 +78,6 @@ }

In the ignore file, you can write some lines of ignored cases like:
In the file-ignore file, you can write some lines to ignore files in [.gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format):
In the case-ignore file, you can write some lines of ignored cases like:
```txt

@@ -128,5 +134,6 @@ ( , )

const configPath = '...' // the config file path
const ignorePath = '...' // the ignore file path
const fileIgnorePath = '...' // the file-ignore file path
const caseIgnorePath = '...' // the case-ignore file path
const config = readRc(dir, configPath, ignorePath)
const config = readRc(dir, configPath, fileIgnorePath, caseIgnorePath)
const output = runWithConfig(value, config)

@@ -145,3 +152,3 @@

- `run(str: string, options?: Options): Result`: Lint a certain file.
- `run(str: string, options?: Options): Result`: Lint a certain content.
- parameters:

@@ -156,4 +163,4 @@ - `str`: The text content you want to lint.

- `logger`: The logger instance, by default it's `console` in Node.js/browser.
- `readRc: (dir: string, config: string, ignore: string, logger?: Console) => Config`: Read config from rc file(s). For rc (run command).
- `runWithConfig(str: string, config: Config): Result`: Lint a certain file with rc config. For rc (run command).
- `readRc: (dir: string, config: string, fileIgnore: string, caseIgnore: string, logger?: Console) => Config`: Read config from rc & ignore file(s).
- `runWithConfig(str: string, config: Config): Result`: Lint a certain content with rc config.

@@ -174,6 +181,6 @@ ### Options

- `rules`: customize the linting config. It could be `undefined` which means linting nothing. It could be `{ preset: 'default' }` which just uses the default config. For more details of `RuleOptions`, please see [supported rules](#supported-rules)
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/hexo.js).
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js).
- `ignoredCases`: provide exception cases which you would like to skip.
- `IgnoredCase`: `{ prefix?, textStart, textEnd?, suffix? }`
- Just follows a certain format inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- Just follows a certain format `[prefix-,]textStart[,textEnd][,-suffix]` inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment).
- `logger`: same to the parameter in `report(...)`.

@@ -186,3 +193,3 @@

- `hyperParsers`: `string[]` (optional)
- `ignores`: `string[]` and the priority is lower than `.zhlintignore`. (optional)
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional)

@@ -221,4 +228,2 @@ ### Output

### Advanced usage
## Features

@@ -288,5 +293,5 @@

*... and this part might be controversial. So if you don't feel well at some point, we definitely would love to know and improve. Opening an [issue](https://github.com/jinjiang/zhlint/issues) is always welcome. Then we could discuss about the possible better option or decision.*
*... and this part might be controversial. So if you don't feel well at some point, we definitely would love to know and improve. Opening an [issue](https://github.com/zhlint-project/zhlint/issues) is always welcome. Then we could discuss about the possible better option or decision.*
```ts
````ts
type RuleOptions = {

@@ -411,3 +416,3 @@ /* PRESET */

/* SPACES AROUND QUOTES */
/* SPACES AROUND QUOTATIONS */

@@ -475,7 +480,12 @@ // default preset: `true`

trimSpace?: boolean
/* SKIP PURE WESTERN SENTENCES */
// default `true`
skipPureWestern?: boolean
}
```
````
## More information
zhlint is now open sourced on [GitHub](https://github.com/zhlint) and [issues](https://github.com/jinjiang/zhlint/issues) welcome.
zhlint is now open sourced on [GitHub](https://github.com/zhlint-project/zhlint) and [issues](https://github.com/zhlint-project/zhlint/issues) welcome.

@@ -43,2 +43,44 @@ # <img src="./docs/logo.svg" style="vertical-align: middle;" /> zhlint

#### 高阶用法
zhlint 还支持 rc 和 ignore 配置文件:
```bash
# 默认为 .zhlintrc
zhlint --config <filepath>
# 默认为 .zhlintignore
zhlint --ignore <filepath>
zhlint --file-ignore <filepath>
# 默认为 .zhlintcaseignore
zhlint --case-ignore <filepath>
# 默认为 current directory
zhlint --dir <path>
```
在 rc 配置文件中,您可以写一个 JSON,例如:
```json
{
"preset": "default",
"rules": {
"adjustedFullwidthPunctuation": ""
}
}
```
关于更多细节,请参见[支持的规则](#支持的规则)。
在 file-ignore 文件中,您可以写多行内容来忽略相应的文件,其语法遵循 [.gitignore 语法](https://git-scm.com/docs/gitignore#_pattern_format):
在 case-ignore 文件中,您可以写多行内容来忽略一些特例,例如:
```txt
( , )
```
关于更多细节:请参见[设置被忽略的特例](#设置被忽略的特例)。
### 作为 Node.js 包

@@ -78,2 +120,22 @@

#### 高阶用法
zhlint 还支持 rc 和 ignore 配置文件:
```js
const { readRc, runWithConfig } = require('zhlint')
const value = '自动在中文和English之间加入空格'
const dir = '...' // 目标文件所在的目录
const configPath = '...' // rc 配置文件路径
const fileIgnorePath = '...' // file-ignore 文件路径
const caseIgnorePath = '...' // case-ignore 文件路径
const config = readRc(dir, configPath, fileIgnorePath, caseIgnorePath)
const output = runWithConfig(value, config)
// ... 后续操作
```
### 作为一个单独的包

@@ -87,3 +149,3 @@

- `run(str: string, options?: Options): Result`:格式化某个文件。
- `run(str: string, options?: Options): Result`:格式化某个文件内容。
- 参数:

@@ -93,7 +155,9 @@ - `str`:需要格式化的文本内容。

- 返回值:
- 针对输入的单个字符串的处理结果。其包好了修复格式之后的文本内容 `value` 以及所有 `validation` 的校验信息。
- `report(results: Result[], logger?: Console): void`:为每个文件打印校验报告。
- 针对输入的单个字符串的处理结果。其包好了修复格式之后的文本内容 `value` 以及所有 `validation` 的格式化信息。
- `report(results: Result[], logger?: Console): void`:为每个文件打印格式化报告。
- 参数:
- `results`:所有格式化结果的数组。
- `logger`:日志处理器实例,默认是 Node.js/浏览器中的 `console`。
- `readRc: (dir: string, config: string, fileIgnore: string, caseIgnore: string, logger?: Console) => Config`:读取配置文件信息。
- `runWithConfig(str: string, config: Config): Result`:通过配置信息格式化特定内容。

@@ -114,3 +178,3 @@ ### 选项

- `rules`:自定义格式化规则,可以是 `undefined` 意味着不做任何格式化,也可以是 `{ preset: 'default' }` 以使用默认配置。关于 `RuleOptions` 的更多细节参见[支持的规则](#支持的规则)。
- `hyperParse`:根据解析器名自定义超文本解析器列表。可以是 `undefined` 以使用默认的[忽略特例的解析器](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/ignore.js)、[Markdown 解析器](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/md.js)以及[Hexo tag 解析器](https://github.com/Jinjiang/zhlint/tree/master/src/hypers/hexo.js)。
- `hyperParse`:根据解析器名自定义超文本解析器列表。可以是 `undefined` 以使用默认的[忽略特例的解析器](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js)、[Markdown 解析器](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js)以及[Hexo tag 解析器](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js)。
- `ignoredCases`:提供想要忽略的特例。

@@ -121,2 +185,9 @@ - `IgnoredCase`:`{ prefix?, textStart, textEnd?, suffix? }`

### RC Config
- `preset`: `string` (可选项)
- `rules`: `RuleOptions` 但不包括 `preset` 字段。(可选项)
- `hyperParsers`: `string[]` (可选项)
- `caseIgnores`: `string[]` 该优先级低于 `.zhlintcaseignore`。(可选项)
### 输出格式

@@ -126,5 +197,10 @@

type Result = {
// 基本信息和文件的可用性
file?: string
disabled: boolean
// 原始的文本内容
origin: string
result: string
// 所有错误信息
validations: Validation[]

@@ -134,5 +210,5 @@ }

type Validation = {
message: string
index: number
length: number
message: string
}

@@ -145,7 +221,7 @@ ```

- `result`:最终修复格式的文本内容。
- `validations`:所有校验信息。
- `validations`:所有格式化信息。
- `Validation`
- `index`:输入的字符串中目标片段所在的索引值。
- `length`:输入的字符串中目标片段的长度。
- `message`:对该校验信息的自然语言描述。
- `message`:对该格式化信息的自然语言描述。

@@ -156,2 +232,4 @@ ## 特性

我们默认支持格式化 Markdown 语法的文本内容。例如:
```js

@@ -161,4 +239,10 @@ run('自动在_中文_和**English**之间加入空格')

这将首先分析 Markdown 语法并提取纯文本内容,然后执行格式化操作。修复后的纯文本内容可以复原为 Markdown 格式字符串,并作为结果中的输出 `value` 返回。
### [Hexo tag](https://hexo.io/docs/tag-plugins) 语法支持
特别地,我们支持 [Hexo tag 语法](https://hexo.io/docs/tag-plugins)。这是因为当我们使用 Hexo 构建 Vue.js 网站时,Markdown 源文件中可能包含一些特殊的标签从而得到不可预测的格式化结果。
因此,我们会默认跳过 Hexo 风格的标签。例如:
```js

@@ -170,3 +254,3 @@ run('现在过滤器只能用在插入文本中 (`{% raw %}{{ }}{% endraw %}` tags)。')

通过 HTML 注释:
在一些特殊的情况下,我们可能会有一些特殊的文本内容不遵循规则。因此,我们可以使用 `ignoredCases` 选项来配置。例如,我们想要保留括号内的空格,这在默认情况下是格式不正确的。不过我们可以在文件的任何地方写一行 HTML 注释:

@@ -192,2 +276,8 @@ ```md

如果你想要忽略整个文件,你也可以添加这个 HTML 注释:
```md
<!-- zhlint disabled -->
```
## 支持的预处理器 (超文本解析器)

@@ -203,5 +293,5 @@

_……这些规则也许存在争议。所以如果你对某些规则不够满意,我们非常希望得到大家的反馈和改进建议。我们也一直欢迎大家来创建 [issue](https://github.com/jinjiang/zhlint/issues),以讨论出可能更好的规则。_
_……这些规则也许存在争议。所以如果你对某些规则不够满意,我们非常希望得到大家的反馈和改进建议。我们也一直欢迎大家来创建 [issue](https://github.com/zhlint-project/zhlint/issues),以讨论出可能更好的规则。_
```ts
````ts
type RuleOptions = {

@@ -326,3 +416,3 @@ /* PRESET */

/* SPACES AROUND QUOTES */
/* SPACES AROUND QUOTATIONS */

@@ -390,3 +480,12 @@ // default preset: `true`

trimSpace?: boolean
/* SKIP PURE WESTERN SENTENCES */
// default `true`
skipPureWestern?: boolean
}
```
````
## 更多信息
zhlint 是一个开源项目,目前源代码在 [GitHub](https://github.com/zhlint-project/zhlint) 上,也欢迎大家来提交 [issue](https://github.com/zhlint-project/zhlint/issues)。

@@ -10,3 +10,3 @@ {

},
"include": ["./src", "./test", "./types"]
"include": ["./src", "./test", "./types", "./vite.config.ts"]
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc