Skip to content

Commit

Permalink
chore: housekeeping + make eslint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 12, 2023
1 parent 6295af8 commit c4741fc
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 162 deletions.
37 changes: 0 additions & 37 deletions .eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('eslint-config-sukka').sukka();
6 changes: 3 additions & 3 deletions example/.nolluprc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
contentBase: './example/public',
port: 9001,
hot: true
contentBase: './example/public',
port: 9001,
hot: true
};
119 changes: 60 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,77 @@
"name": "disqusjs",
"version": "3.0.3-canary.1",
"description": "Alternative DISQUS - Render comments components from Disqus API",
"homepage": "https://disqusjs.skk.moe",
"repository": {
"type": "git",
"url": "git+https://github.com/SukkaW/disqusjs.git"
},
"bugs": {
"url": "https://github.com/SukkaW/disqusjs/issues"
},
"main": "dist/disqusjs.es2015.umd.js",
"types": "dist/disqusjs.es2015.umd.d.ts",
"module": "dist/disqusjs.es2015.es.mjs",
"types": "dist/disqusjs.es2015.umd.d.ts",
"files": [
"dist/**/*",
"LICENSE"
"LICENSE",
"dist/**/*"
],
"exports": {
"./dist/": "./dist/",
"./package.json": "./package.json",
"./styles/disqusjs.css": "./dist/styles/disqusjs.css",
".": {
"types": "./dist/disqusjs.es2015.umd.d.ts",
"module": "./dist/disqusjs.es2015.es.js",
"import": "./dist/disqusjs.es2015.es.mjs",
"module": "./dist/disqusjs.es2015.es.js",
"default": "./dist/disqusjs.es2015.umd.js"
},
"./es2015": {
"types": "./dist/disqusjs.es2015.umd.d.ts",
"module": "./dist/disqusjs.es2015.es.js",
"import": "./dist/disqusjs.es2015.es.mjs",
"module": "./dist/disqusjs.es2015.es.js",
"default": "./dist/disqusjs.es2015.umd.js"
},
"./es2017": {
"types": "./dist/disqusjs.es2017.umd.d.ts",
"module": "./dist/disqusjs.es2017.es.js",
"import": "./dist/disqusjs.es2017.es.mjs",
"module": "./dist/disqusjs.es2017.es.js",
"default": "./dist/disqusjs.es2017.umd.js"
},
"./es2022": {
"types": "./dist/disqusjs.es2022.umd.d.ts",
"module": "./dist/disqusjs.es2022.es.js",
"import": "./dist/disqusjs.es2022.es.mjs",
"module": "./dist/disqusjs.es2022.es.js",
"default": "./dist/disqusjs.es2022.umd.js"
},
"./react/styles/disqusjs.css": "./dist/react/styles/disqusjs.css",
"./react": {
"types": "./dist/react/disqusjs.es2015.cjs.d.ts",
"module": "./dist/react/disqusjs.es2015.es.js",
"import": "./dist/react/disqusjs.es2015.es.mjs",
"module": "./dist/react/disqusjs.es2015.es.js",
"default": "./dist/react/disqusjs.es2015.cjs.js"
},
"./react/es2015": {
"types": "./dist/react/disqusjs.es2015.cjs.d.ts",
"module": "./dist/react/disqusjs.es2015.es.js",
"import": "./dist/react/disqusjs.es2015.es.mjs",
"module": "./dist/react/disqusjs.es2015.es.js",
"default": "./dist/react/disqusjs.es2015.cjs.js"
},
"./react/es2017": {
"types": "./dist/react/disqusjs.es2017.cjs.d.ts",
"module": "./dist/react/disqusjs.es2017.es.js",
"import": "./dist/react/disqusjs.es2017.es.mjs",
"module": "./dist/react/disqusjs.es2017.es.js",
"default": "./dist/react/disqusjs.es2017.cjs.js"
},
"./react/es2022": {
"types": "./dist/react/disqusjs.es2022.cjs.d.ts",
"module": "./dist/react/disqusjs.es2022.es.js",
"import": "./dist/react/disqusjs.es2022.es.mjs",
"module": "./dist/react/disqusjs.es2022.es.js",
"default": "./dist/react/disqusjs.es2022.cjs.js"
},
"./browser": {
"module": "./dist/browser/disqusjs.es2018.es.min.js",
"import": "./dist/browser/disqusjs.es2018.es.min.mjs",
"module": "./dist/browser/disqusjs.es2018.es.min.js",
"default": "./dist/browser/disqusjs.es2015.umd.min.js"
}
},
Expand All @@ -75,11 +83,8 @@
"prepublishOnly": "npm run build",
"prebuild:analyze": "rimraf dist",
"build:analyze": "cross-env NODE_ENV=production ANALYZE=true rollup --configPlugin swc3 -c rollup.config.ts",
"dev": "nollup -c ./example/rollup.config.js --rc ./example/.nolluprc.js --environment NODE_ENV:development"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SukkaW/disqusjs.git"
"dev": "nollup -c ./example/rollup.config.js --rc ./example/.nolluprc.js --environment NODE_ENV:development",
"lint": "eslint --format=sukka ."
},
"keywords": [
"Disqus",
Expand All @@ -90,63 +95,58 @@
],
"author": "Sukka <https://skk.moe>",
"license": "MIT",
"bugs": {
"url": "https://github.com/SukkaW/disqusjs/issues"
},
"homepage": "https://disqusjs.skk.moe",
"peerDependencies": {
"preact": "^10.7.1",
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"preact": {
"optional": true
}
"dependencies": {
"foxact": "^0.2.26"
},
"devDependencies": {
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"@swc/core": "^1.3.74",
"@swc/helpers": "^0.5.1",
"@types/node": "^18.17.5",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"@eslint-sukka/node": "^4.1.7",
"@eslint-sukka/react": "^4.1.7",
"@eslint-sukka/ts": "^4.1.7",
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@swc/core": "^1.3.96",
"@swc/helpers": "^0.5.3",
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"cross-env": "^7.0.3",
"eslint": "^8.47.0",
"eslint-config-sukka": "^3.0.4",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.0-2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint": "^8.53.0",
"eslint-config-sukka": "^4.1.7",
"eslint-formatter-sukka": "^4.1.7",
"nollup": "^0.21.0",
"preact": "^10.16.0",
"preact": "^10.19.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-refresh": "^0.9.0",
"rimraf": "^5.0.1",
"rollup": "^3.28.0",
"rimraf": "^5.0.5",
"rollup": "^4.4.0",
"rollup-plugin-bundle-analyzer": "^1.6.6",
"rollup-plugin-commonjs-alternate": "^0.8.0",
"rollup-plugin-dts": "^5.3.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-hot-css": "^0.7.2",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-react-refresh": "^0.0.3",
"rollup-plugin-static-files": "^0.2.0",
"rollup-plugin-swc3": "^0.9.1",
"sass": "^1.65.1"
"rollup-plugin-swc3": "^0.10.3",
"sass": "^1.69.5"
},
"dependencies": {
"eslint-plugin-n": "^16.0.1",
"foxact": "^0.2.20"
"peerDependencies": {
"preact": "^10.7.1",
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"preact": {
"optional": true
}
},
"overrides": {
"rollup": "$rollup",
"eslint-plugin-import": "npm:eslint-plugin-i@latest",
"function-bind": "npm:@nolyfill/function-bind@latest",
"has": "npm:@nolyfill/has@latest",
"has-proto": "npm:@nolyfill/has-proto@latest",
Expand All @@ -161,6 +161,7 @@
"object.fromentries": "npm:@nolyfill/object.fromentries@latest",
"object.hasown": "npm:@nolyfill/object.hasown@latest",
"object.values": "npm:@nolyfill/object.values@latest",
"string.prototype.matchall": "npm:@nolyfill/string.prototype.matchall@latest"
"string.prototype.matchall": "npm:@nolyfill/string.prototype.matchall@latest",
"side-channel": "npm:@nolyfill/side-channel@latest"
}
}
3 changes: 1 addition & 2 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,13 @@ function stringHash(str: string) {
let i = str.length;

while (i) {
// eslint-disable-next-line no-bitwise -- performance
hash = (hash * 33) ^ str.charCodeAt(--i);
}

/* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
* integers. Since we want the results to be always positive, convert the
* signed int to an unsigned by doing an unsigned bitshift. */
// eslint-disable-next-line no-bitwise -- performance

return hash >>> 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function DisqusJSPostItem({ comment, children, nesting }: DisqusJSCommentASTItem
)
}
{' '}
<span className="dsqjs-bullet"></span>
<span className="dsqjs-bullet" />
{' '}
{
comment.createdAt && (
Expand All @@ -64,7 +64,7 @@ function DisqusJSPostItem({ comment, children, nesting }: DisqusJSCommentASTItem
}
</div>
</div>
<DisqusJSChildrenPostItems children={children} nesting={nesting} />
<DisqusJSChildrenPostItems nesting={nesting}>{children}</DisqusJSChildrenPostItems>
{comment.hasMore && <p className="dsqjs-has-more">切换至 <DisqusJSForceDisqusModeButton>完整 Disqus 模式</DisqusJSForceDisqusModeButton> 显示更多回复</p>}
</li>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Disqus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const Disqus = memo(({
}

const getDisqusConfig = () => {
/* eslint-disable react/no-this-in-sfc -- "this" refers to Disqus config object */
return function (this: any) {
if (identifier) {
this.page.identifier = identifier;
Expand All @@ -85,6 +86,7 @@ export const Disqus = memo(({
}
];
};
/* eslint-enable react/no-this-in-sfc */
};

if (window.DISQUS && document.getElementById(EMBED_SCRIPT_ID)) {
Expand Down
31 changes: 16 additions & 15 deletions src/components/Disscussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ const DisqusJSSortTypeRadio = ({
title,
label
}: DisqusJSSortTypeRadioProps) => {
return <>
<input
className="dsqjs-order-radio"
id={`dsqjs-order-${sortType}`}
type="radio"
name="comment-order"
value={sortType}
onChange={onChange}
checked={checked}
/>
<label className="dsqjs-order-label" htmlFor={`dsqjs-order-${sortType}`} title={title}>{label}</label>
</>;
return (
<>
<input
className="dsqjs-order-radio"
id={`dsqjs-order-${sortType}`}
type="radio"
name="comment-order"
value={sortType}
onChange={onChange}
checked={checked}
/>
<label className="dsqjs-order-label" htmlFor={`dsqjs-order-${sortType}`} title={title}>{label}</label>
</>
);
};

const DisqusJSSortTypeRadioGroup = memo(() => {
Expand Down Expand Up @@ -169,7 +171,7 @@ const DisqusJSPosts = ({ id }: { id: string }) => {
}
}, [posts, resetAndFetchFirstPageOfPosts, id, isLoadingMorePosts, sortType]);

const comments = useMemo(() => posts.filter(Boolean).map(i => i.response).flat(), [posts]);
const comments = useMemo(() => posts.filter(Boolean).flatMap(i => i.response), [posts]);

if (posts.length > 0) {
return (
Expand Down Expand Up @@ -262,8 +264,7 @@ export const DisqusJSThread = () => {
<DisqusJSHeader totalComments={totalComments} siteName={siteName ?? ''} />
{totalComments === 0
? <DisqusJSNoComment text={nocomment ?? '这里空荡荡的,一个人都没有'} />
: <DisqusJSPosts id={matchedThread.id} />
}
: <DisqusJSPosts id={matchedThread.id} />}
</>
);
};
8 changes: 4 additions & 4 deletions src/components/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { DisqusJSForceDisqusModeButton, DisqusJSReTestModeButton, DisqusJSRetryB

export const DisqusJSError = memo(() => (
<div id="dsqjs-msg">
评论基础模式加载失败,请
评论基础模式加载失败,请
{' '}
<DisqusJSRetryButton>重载</DisqusJSRetryButton>
{' '}
{' '}
<DisqusJSReTestModeButton>尝试完整 Disqus 模式</DisqusJSReTestModeButton>
</div>
));

export const DisqusJSCreateThread = memo(() => (
<div id="dsqjs-msg">
当前 Thread 尚未创建。是否切换至
当前 Thread 尚未创建。是否切换至
{' '}
<DisqusJSForceDisqusModeButton>完整 Disqus 模式</DisqusJSForceDisqusModeButton>
</div>
));

Expand Down
Loading

0 comments on commit c4741fc

Please sign in to comment.