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.6.1 to 0.6.2

3

bin/index.js

@@ -39,4 +39,3 @@ #!/usr/bin/env node

const help = () =>
console.log(helpMessage)
const help = () => console.log(helpMessage)

@@ -43,0 +42,0 @@ if (argv.v || argv.version) {

@@ -77,3 +77,3 @@ export declare type Block = {

*/
INDETERMINATED = 'indeterminated',
INDETERMINATED = 'indeterminated'
}

@@ -166,2 +166,3 @@

fullWidthPunctuation?: string
adjustedFullWidthPunctuation?: string
unifiedPunctuation?: 'traditional' | 'simplified'

@@ -209,3 +210,3 @@

* @deprecated
*
*
* Please use `noSpaceInsideWrapper` instead.

@@ -216,3 +217,3 @@ */

* @deprecated
*
*
* Please use `spaceBetweenHalfWidthLetters` instead.

@@ -223,3 +224,3 @@ */

* @deprecated
*
*
* Please use `noSpaceBetweenFullWidthLetters` instead.

@@ -230,3 +231,3 @@ */

* @deprecated
*
*
* Please use `spaceBetweenMixedWidthLetters` instead.

@@ -233,0 +234,0 @@ */

@@ -11,3 +11,9 @@ "use strict";

// - `(:::)` + `(?=\n|$)`
const matcher = /(?<=^|\n)(:::.*)\n([\s\S]+?)\n(:::)(?=\n|$)/g;
let matcher;
try {
matcher = new RegExp('(?<=^|\\n)(:::.*)\\n([\\s\\S]+?)\\n(:::)(?=\\n|$)', 'g');
}
catch (_a) {
matcher = /(:::.*)\n([\s\S]+?)\n(:::)/g;
}
const parser = (data) => {

@@ -14,0 +20,0 @@ data.modifiedContent = data.modifiedContent.replace(matcher, (raw, start, content, end, index) => {

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

noSpaceBetweenFullWidthContent: 'noSpaceBetweenFullWidthLetters',
spaceBetweenMixedWidthContent: 'spaceBetweenMixedWidthLetters',
spaceBetweenMixedWidthContent: 'spaceBetweenMixedWidthLetters'
};

@@ -65,4 +65,3 @@ const deprecateOptions = (ruleOption, logger) => {

else {
hyperParse =
options.hyperParse || hyperParseInfo.map((item) => item.name);
hyperParse = options.hyperParse || hyperParseInfo.map((item) => item.name);
}

@@ -69,0 +68,0 @@ const normoalizedOptions = {

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

const isVisibleType = (type) => {
return (0, exports.isNonCodeVisibleType)(type) || type === HyperTokenType.HYPER_CONTENT_CODE;
return ((0, exports.isNonCodeVisibleType)(type) || type === HyperTokenType.HYPER_CONTENT_CODE);
};

@@ -128,0 +128,0 @@ exports.isVisibleType = isVisibleType;

@@ -324,6 +324,3 @@ "use strict";

const nextType = (0, char_1.checkCharType)(nextChar);
if (nextType === types_1.CharType.LETTERS_HALF) {
return true;
}
if (nextType === types_1.CharType.SPACE) {
if (nextType === types_1.CharType.LETTERS_HALF || nextType === types_1.CharType.SPACE) {
if (!status.lastGroup) {

@@ -330,0 +327,0 @@ return true;

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

})(ValidationTarget = exports.ValidationTarget || (exports.ValidationTarget = {}));
const adjustedFullWidthPunctuations = `“”‘’`;
const generateMarker = (str, index) => {

@@ -57,7 +58,9 @@ const prefix = str.substring(0, index);

if (charType === parser_1.CharType.LETTERS_FULL ||
charType === parser_1.CharType.PUNCTUATION_FULL) {
(charType === parser_1.CharType.PUNCTUATION_FULL &&
adjustedFullWidthPunctuations.indexOf(prefix[i]) === -1)) {
fullWidthCount++;
}
else if (charType === parser_1.CharType.LETTERS_HALF ||
charType === parser_1.CharType.PUNCTUATION_HALF ||
(charType === parser_1.CharType.PUNCTUATION_HALF &&
adjustedFullWidthPunctuations.indexOf(prefix[i]) !== -1) ||
charType === parser_1.CharType.SPACE) {

@@ -64,0 +67,0 @@ halfWidthCount++;

@@ -69,3 +69,5 @@ "use strict";

const tokenAfter = (0, util_1.findTokenAfter)(group, token);
if (tokenAfter && tokenAfter.type === parser_1.CharType.LETTERS_HALF && !token.spaceAfter) {
if (tokenAfter &&
tokenAfter.type === parser_1.CharType.LETTERS_HALF &&
!token.spaceAfter) {
return;

@@ -72,0 +74,0 @@ }

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

fullWidthPunctuation: `,。:;?!“”‘’`,
adjustedFullWidthPunctuation: `“”‘’`,
unifiedPunctuation: 'simplified',

@@ -43,0 +44,0 @@ spaceBetweenHalfWidthLetters: true,

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

[QuoteType.RIGHT_EMBEDDED]: `’`,
[QuoteType.RIGHT]: `”`,
[QuoteType.RIGHT]: `”`
},

@@ -35,4 +35,4 @@ traditional: {

[QuoteType.RIGHT_EMBEDDED]: `』`,
[QuoteType.RIGHT]: `」`,
},
[QuoteType.RIGHT]: `」`
}
};

@@ -65,3 +65,5 @@ const valueToKey = (obj) => {

const unifiedMap = replaceMap[unifiedOption];
const objectMap = valueToKey(unifiedOption === 'simplified' ? replaceMap.traditional : replaceMap.simplified);
const objectMap = valueToKey(unifiedOption === 'simplified'
? replaceMap.traditional
: replaceMap.simplified);
const handlerPunctuationUnified = (token) => {

@@ -68,0 +70,0 @@ if (token.type !== parser_1.GroupTokenType.GROUP) {

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

* - fullWidthPunctuation: string = `,。:;?!“”‘’`
* - adjustedFullWidthPunctuation: string = `“”‘’`
*

@@ -37,5 +38,12 @@ * Details:

const defaultFullWidthOption = `,。:;?!“”‘’`;
const defaultAdjustedFullWidthOption = `“”‘’`;
const checkAdjusted = (token, adjusted) => {
if (adjusted.indexOf(token.modifiedContent) >= 0) {
token.modifiedType = parser_1.CharType.PUNCTUATION_HALF;
}
};
const parseOptions = (options) => {
const halfWidthOption = (options === null || options === void 0 ? void 0 : options.halfWidthPunctuation) || '';
const fullWidthOption = (options === null || options === void 0 ? void 0 : options.fullWidthPunctuation) || '';
const adjustedFullWidthOption = (options === null || options === void 0 ? void 0 : options.adjustedFullWidthPunctuation) || '';
const halfWidthMap = {};

@@ -65,7 +73,8 @@ const fullWidthMap = {};

fullWidthMap,
fullWidthPairMap
fullWidthPairMap,
adjusted: adjustedFullWidthOption
};
};
const generateHandler = (options) => {
const { halfWidthMap, fullWidthMap, fullWidthPairMap } = parseOptions(options);
const { halfWidthMap, fullWidthMap, fullWidthPairMap, adjusted } = parseOptions(options);
const handleHyperSpaceOption = (token, _, group) => {

@@ -93,2 +102,3 @@ // skip non-punctuation/quote/bracket situations

(0, util_1.checkContent)(token, fullWidthMap[content], parser_1.CharType.PUNCTUATION_FULL, messages_1.PUNCTUATION_FULL_WIDTH);
checkAdjusted(token, adjusted);
}

@@ -120,4 +130,5 @@ else if (halfWidthMap[content]) {

halfWidthPunctuation: defaultHalfWidthOption,
fullWidthPunctuation: defaultFullWidthOption
fullWidthPunctuation: defaultFullWidthOption,
adjustedFullWidthPunctuation: defaultAdjustedFullWidthOption
};
exports.default = generateHandler;

@@ -30,2 +30,5 @@ "use strict";

const messages_1 = require("./messages");
const isFullWidth = (char, adjusted) => {
return (0, parser_1.isFullWidthPair)(char) && adjusted.indexOf(char) === -1;
};
const shouldSkip = (before, beforeTokenSeq, token, afterTokenSeq, after) => {

@@ -61,2 +64,3 @@ if (!before || !after) {

const noSpaceOutsideFullBracketOption = options.noSpaceOutsideFullBracket;
const adjustedFullWidthOption = options.adjustedFullWidthPunctuation || '';
return (token, _, group) => {

@@ -98,3 +102,3 @@ // skip non-bracket tokens

noSpaceOutsideFullBracketOption) {
const isFullWidth = (0, parser_1.isFullWidthPair)(token.modifiedContent);
const fullWidth = isFullWidth(token.modifiedContent, adjustedFullWidthOption);
// 2.1 right-bracket x left-bracket

@@ -105,3 +109,4 @@ if (contentTokenAfter) {

if (afterSpaceHost) {
const hasFullWidth = isFullWidth || (0, parser_1.isFullWidthPair)(contentTokenAfter.modifiedContent);
const hasFullWidth = fullWidth ||
isFullWidth(contentTokenAfter.modifiedContent, adjustedFullWidthOption);
// 2.1.1 any-full-bracket

@@ -139,5 +144,5 @@ // 2.1.2 right-half-bracket x left-half-bracket

// 2.2.2 content/right-quote/code x left-half-bracket
if (isFullWidth ||
if (fullWidth ||
(contentTokenBefore.type === parser_1.GroupTokenType.GROUP &&
(0, parser_1.isFullWidthPair)(contentTokenBefore.modifiedEndContent))) {
isFullWidth(contentTokenBefore.modifiedEndContent, adjustedFullWidthOption))) {
if (noSpaceOutsideFullBracketOption) {

@@ -167,5 +172,5 @@ (0, util_1.checkSpaceAfter)(beforeSpaceHost, '', messages_1.BRACKET_NOSPACE_OUTSIDE);

// 2.4.2 right-half-bracket x content/left-quote/code
if (isFullWidth ||
if (fullWidth ||
(contentTokenAfter.type === parser_1.GroupTokenType.GROUP &&
(0, parser_1.isFullWidthPair)(contentTokenAfter.modifiedStartContent))) {
isFullWidth(contentTokenAfter.modifiedStartContent, adjustedFullWidthOption))) {
if (noSpaceOutsideFullBracketOption) {

@@ -172,0 +177,0 @@ (0, util_1.checkSpaceAfter)(afterSpaceHost, '', messages_1.BRACKET_NOSPACE_OUTSIDE);

@@ -31,2 +31,5 @@ "use strict";

const messages_1 = require("./messages");
const isFullWidth = (char, adjusted) => {
return (0, parser_1.isFullWidthPair)(char) && adjusted.indexOf(char) === -1;
};
const generateHandler = (options) => {

@@ -36,2 +39,3 @@ const noSpaceInsideQuoteOption = options.noSpaceInsideQuote;

const noSpaceOutsideFullQuoteOption = options.noSpaceOutsideFullQuote;
const adjustedFullWidthOption = options.adjustedFullWidthPunctuation || '';
return (token, _, group) => {

@@ -69,7 +73,7 @@ // skip non-group tokens

if (spaceHost) {
const isFullWidth = (0, parser_1.isFullWidthPair)(token.modifiedEndContent) ||
(0, parser_1.isFullWidthPair)(contentTokenAfter.modifiedStartContent);
const fullWidth = isFullWidth(token.modifiedEndContent, adjustedFullWidthOption) ||
isFullWidth(contentTokenAfter.modifiedStartContent, adjustedFullWidthOption);
// 2.1.1 right-full-quote x left-full-quote
// 2.1.2 right-half-quote x left-half-quote
if (isFullWidth) {
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {

@@ -97,6 +101,6 @@ (0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_SPACE_OUTSIDE);

if (spaceHost) {
const isFullWidth = (0, parser_1.isFullWidthPair)(token.modifiedStartContent);
const fullWidth = isFullWidth(token.modifiedStartContent, adjustedFullWidthOption);
// 2.2.1 content/code x left-full-quote
// 2.2.2 content/code x left-half-quote
if (isFullWidth) {
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {

@@ -117,3 +121,3 @@ (0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_NOSPACE_OUTSIDE);

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

@@ -124,6 +128,6 @@ ((0, parser_1.isLettersType)(contentTokenAfter.type) ||

if (spaceHost) {
const isFullWidth = (0, parser_1.isFullWidthPair)(token.modifiedEndContent);
const fullWidth = isFullWidth(token.modifiedEndContent, adjustedFullWidthOption);
// 2.3.1 right-full-quote x content/code
// 2.3.2 right-half-quote x content/code
if (isFullWidth) {
if (fullWidth) {
if (noSpaceOutsideFullQuoteOption) {

@@ -130,0 +134,0 @@ (0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTE_NOSPACE_OUTSIDE);

@@ -42,4 +42,3 @@ "use strict";

// skip non-mark situations
if (!(0, util_1.isWrapper)(token) &&
!(0, util_1.isWrapper)(tokenAfter)) {
if (!(0, util_1.isWrapper)(token) && !(0, util_1.isWrapper)(tokenAfter)) {
return;

@@ -55,8 +54,6 @@ }

}
else if (markSideBefore === parser_1.MarkSideType.LEFT &&
!(0, util_1.isWrapper)(tokenAfter)) {
else if (markSideBefore === parser_1.MarkSideType.LEFT && !(0, util_1.isWrapper)(tokenAfter)) {
(0, util_1.checkSpaceAfter)(token, '', messages_1.MARKDOWN_NOSPACE_INSIDE);
}
else if (markSideAfter === parser_1.MarkSideType.RIGHT &&
!(0, util_1.isWrapper)(token)) {
else if (markSideAfter === parser_1.MarkSideType.RIGHT && !(0, util_1.isWrapper)(token)) {
(0, util_1.checkSpaceAfter)(token, '', messages_1.MARKDOWN_NOSPACE_INSIDE);

@@ -63,0 +60,0 @@ }

@@ -236,4 +236,3 @@ "use strict";

const nextToken = (0, exports.findTokenAfter)(group, target);
if (nextToken &&
(0, exports.getWrapperSide)(nextToken) === parser_1.MarkSideType.LEFT) {
if (nextToken && (0, exports.getWrapperSide)(nextToken) === parser_1.MarkSideType.LEFT) {
return target;

@@ -240,0 +239,0 @@ }

{
"name": "zhlint",
"version": "0.6.1",
"version": "0.6.2",
"description": "A linting tool for Chinese language.",

@@ -73,4 +73,6 @@ "bin": {

"build:type": "api-extractor run --local --verbose",
"format": "prettier --write .",
"lint": "eslint {src,test,types}/**.ts --fix",
"lint": "prettier --check .",
"lint:fix": "prettier --write .",
"lint:eslint": "eslint {src,test,types}/**.ts",
"lint:eslint:fix": "eslint {src,test,types}/**.ts --fix",
"test": "vitest run",

@@ -77,0 +79,0 @@ "coverage": "vitest run --coverage",

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

const value = '自动在中文和English之间加入空格'
const options = { rules: { preset: 'default' }}
const options = { rules: { preset: 'default' } }
const output = run(value, options)

@@ -168,3 +168,6 @@

```js
run('现在过滤器只能用在插入文本中 (`{% raw %}{{ }}{% endraw %}` tags)。', options)
run(
'现在过滤器只能用在插入文本中 (`{% raw %}{{ }}{% endraw %}` tags)。',
options
)
```

@@ -227,2 +230,9 @@

// Treat these full-width punctuations as half-fullWidthPunctuation
// when processing the spaces issues around them.
// Since something like quotes in morder Chinese fonts are
// only rendered in half-width.
// default preset: `“”‘’`
adjustedFullWidthPunctuation?: string
// Convert traditional Chinese punctuations into simplified ones or vice versa.

@@ -356,2 +366,1 @@ // default preset: `simplified`

zhlint is now open sourced on [GitHub](https://github.com/zhlint) and [issues](https://github.com/jinjiang/zhlint/issues) welcome.

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