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

Replace 3rd-party type definitions #4857

Merged
merged 2 commits into from
Jul 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rules/function-calc-no-unspaced-operator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ function rule(actual) {
return;
}

const parensMatch = balancedMatch('(', ')', valueParser.stringify(node));
const nodeText = valueParser.stringify(node);
const parensMatch = balancedMatch('(', ')', nodeText);

if (!parensMatch) {
throw new Error(`No parens match: "${nodeText}"`);
}

const rawExpression = parensMatch.body;
const expressionIndex =
decl.source.start.column +
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/FileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const path = require('path');
const DEFAULT_CACHE_LOCATION = './.stylelintcache';
const DEFAULT_HASH = '';

/** @typedef {import('file-entry-cache').FileDescriptor["meta"] & { hashOfConfig?: string }} CacheMetadata */

/**
* @param {string} [cacheLocation]
* @param {string} [hashOfConfig]
Expand All @@ -30,6 +32,7 @@ class FileCache {
// Get file descriptor compares current metadata against cached
// one and stores the result to "changed" prop.w
const descriptor = this._fileCache.getFileDescriptor(absoluteFilepath);
/** @type {CacheMetadata} */
const meta = descriptor.meta || {};
const changed = descriptor.changed || meta.hashOfConfig !== this._hashOfConfig;

Expand Down
9 changes: 7 additions & 2 deletions lib/utils/blurFunctionArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ module.exports = function (source, functionName, blurChar = '`') {
while (lowerCaseSource.includes(nameWithParen, searchStartIndex)) {
const openingParenIndex =
lowerCaseSource.indexOf(nameWithParen, searchStartIndex) + functionNameLength;
const closingParenIndex =
balancedMatch('(', ')', lowerCaseSource.slice(openingParenIndex)).end + openingParenIndex;
const parensMatch = balancedMatch('(', ')', lowerCaseSource.slice(openingParenIndex));

if (!parensMatch) {
throw new Error(`No parens match: "${source}"`);
}

const closingParenIndex = parensMatch.end + openingParenIndex;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] Unless checking !parensMatch, the following type error occurs:

lib/utils/blurFunctionArguments.js:42:41 - error TS2339: Property 'end' does not exist on type 'void | Output'.
  Property 'end' does not exist on type 'void'.

42  	const closingParenIndex = parensMatch.end + openingParenIndex;
    	                                      ~~~

const argumentsLength = closingParenIndex - openingParenIndex - 1;

result =
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/functionArgumentsSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = function (source, functionName, callback) {

const parensMatch = balancedMatch('(', ')', source.substr(match.startIndex));

if (!parensMatch) {
throw new Error(`No parens match: "${source}"`);
}

callback(parensMatch.body, match.endIndex + 1);
},
);
Expand Down
2 changes: 1 addition & 1 deletion lib/writeOutputFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const writeFileAtomic = require('write-file-atomic');
/**
* @param {string} content
* @param {string} filePath
* @returns {Promise<Error | undefined>}
* @returns {Promise<void>}
*/
module.exports = (content, filePath) =>
writeFileAtomic(path.normalize(filePath), stripAnsi(content));
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,19 @@
"devDependencies": {
"@stylelint/prettier-config": "^2.0.0",
"@stylelint/remark-preset": "^1.0.0",
"@types/balanced-match": "^1.0.1",
"@types/browserslist": "^4.8.0",
"@types/debug": "^4.1.5",
"@types/file-entry-cache": "^5.0.1",
"@types/global-modules": "^2.0.0",
"@types/globjoin": "^0.1.0",
"@types/imurmurhash": "^0.1.1",
"@types/lodash": "^4.14.155",
"@types/micromatch": "^4.0.1",
"@types/postcss-safe-parser": "^4.0.0",
"@types/style-search": "^0.1.1",
"@types/svg-tags": "^1.0.0",
"@types/write-file-atomic": "^3.0.1",
"benchmark": "^2.1.4",
"common-tags": "^1.8.0",
"del": "^5.1.0",
Expand Down
5 changes: 0 additions & 5 deletions types/balanced-match/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions types/file-entry-cache/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions types/imurmurhash/index.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions types/postcss/extensions.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions types/style-search/index.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions types/svg-tags/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion types/svg-tags/postcss-safe-parser.ts

This file was deleted.

21 changes: 0 additions & 21 deletions types/write-file-atomic/index.d.ts

This file was deleted.