зеркало из https://github.com/mozilla/addons-blog.git
Configure ESLint (#28)
This commit is contained in:
Родитель
f0ac17ffa7
Коммит
c038b9e58f
|
@ -42,6 +42,7 @@ jobs:
|
|||
- *run_yarn_install
|
||||
- *save_build_cache
|
||||
- run: yarn prettier-ci
|
||||
- run: yarn lint:js
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"extends": [
|
||||
"amo",
|
||||
],
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"import/no-extraneous-dependencies": ["error", {
|
||||
"devDependencies": true
|
||||
}]
|
||||
}
|
||||
}
|
16
.eslintrc.js
16
.eslintrc.js
|
@ -1,16 +0,0 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
},
|
||||
plugins: ['prettier'],
|
||||
extends: ['prettier'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
},
|
||||
rules: {
|
||||
'prettier/prettier': 'error',
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
quotes: ['error', 'single'],
|
||||
semi: ['error', 'always'],
|
||||
},
|
||||
};
|
|
@ -8,19 +8,17 @@ const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
|
|||
const xmlFiltersPlugin = require('eleventy-xml-plugin');
|
||||
const Nunjucks = require('nunjucks');
|
||||
|
||||
const slugify = require('./libs/slugify');
|
||||
|
||||
const inputDir = path.relative(__dirname, 'src/content');
|
||||
const wpInputDir = path.relative(__dirname, 'src/wp-content');
|
||||
const outputDir = path.relative(__dirname, 'build');
|
||||
|
||||
const buildWordpressTheme = process.env.BUILD_WORDPRESS_THEME === '1';
|
||||
|
||||
const window = new JSDOM('').window;
|
||||
const { window } = new JSDOM('');
|
||||
const DOMPurify = createDOMPurify(window);
|
||||
const defaultNunjucksEnv = new Nunjucks.Environment();
|
||||
|
||||
module.exports = function (eleventyConfig) {
|
||||
module.exports = function configure(eleventyConfig) {
|
||||
// Tell the config to not use gitignore for ignores.
|
||||
eleventyConfig.setUseGitIgnore(false);
|
||||
|
||||
|
@ -30,6 +28,7 @@ module.exports = function (eleventyConfig) {
|
|||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
return defaultNunjucksEnv.filters.safe(
|
||||
DOMPurify.sanitize(value.toString())
|
||||
);
|
||||
|
@ -45,7 +44,7 @@ module.exports = function (eleventyConfig) {
|
|||
|
||||
eleventyConfig.addFilter('postAuthors', (allAuthors, postAuthor) => {
|
||||
return allAuthors.filter((item) => {
|
||||
return postAuthor == item.id;
|
||||
return postAuthor === item.id;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -57,11 +56,14 @@ module.exports = function (eleventyConfig) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (postIndex >= 0 && allPosts && allPosts.length) {
|
||||
if (postIndex + modifier >= 0 && postIndex + modifier < allPosts.length) {
|
||||
return allPosts[postIndex + modifier];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
eleventyConfig.addFilter('getPrevPost', (allPosts, currentPost) => {
|
||||
|
@ -72,8 +74,6 @@ module.exports = function (eleventyConfig) {
|
|||
return getPost(allPosts, currentPost, 1);
|
||||
});
|
||||
|
||||
eleventyConfig.addFilter('slugify', slugify);
|
||||
|
||||
// Explicitly copy through the built files needed.
|
||||
eleventyConfig.addPassthroughCopy({
|
||||
'./src/content/robots.txt': 'robots.txt',
|
||||
|
@ -89,7 +89,7 @@ module.exports = function (eleventyConfig) {
|
|||
|
||||
eleventyConfig.setBrowserSyncConfig({
|
||||
callbacks: {
|
||||
ready: function (err, bs) {
|
||||
ready(err, bs) {
|
||||
bs.addMiddleware('*', (req, res) => {
|
||||
const content_404 = fs.readFileSync('./build/404.html');
|
||||
// Provides the 404 content without redirect.
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
const slugify = require('slugify');
|
||||
|
||||
module.exports = (() => {
|
||||
const slugifier = (string) =>
|
||||
slugify(string, {
|
||||
replacement: '-',
|
||||
lower: true,
|
||||
});
|
||||
return slugifier;
|
||||
})();
|
|
@ -22,7 +22,8 @@
|
|||
"sass:watch": "chokidar 'src/assets/css/**/*.scss' -c 'npm run sass:build'",
|
||||
"script:build": "bin/build-script",
|
||||
"script:watch": "chokidar 'src/assets/js/*.js' -c 'npm run script:build'",
|
||||
"lint:php": "find build -name '*.php' -print0 | xargs -0 -n1 -P8 php -l"
|
||||
"lint:php": "find build -name '*.php' -print0 | xargs -0 -n1 -P8 php -l",
|
||||
"lint:js": "eslint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@11ty/eleventy": "^0.11.1",
|
||||
|
@ -31,9 +32,11 @@
|
|||
"chokidar-cli": "^2.1.0",
|
||||
"dompurify": "^2.2.6",
|
||||
"eleventy-xml-plugin": "^0.1.0",
|
||||
"eslint": "^7.21.0",
|
||||
"eslint": "^7.22.0",
|
||||
"eslint-config-amo": "^4.3.0",
|
||||
"flat-cache": "^3.0.4",
|
||||
"fs-extra": "^9.1.0",
|
||||
"jest": "^26.6.3",
|
||||
"jsdom": "^16.5.1",
|
||||
"luxon": "^1.26.0",
|
||||
"markdown-it-container": "^3.0.0",
|
||||
|
@ -41,6 +44,7 @@
|
|||
"node-sass": "^5.0.0",
|
||||
"normalize.css": "^8.0.1",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nunjucks": "^3.2.3",
|
||||
"photon-colors": "^3.3.2",
|
||||
"prettier": "^2.2.1",
|
||||
"pretty-quick": "^3.1.0",
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
(function () {
|
||||
/* global window, document */
|
||||
(function newTabLinks() {
|
||||
const links = document.querySelectorAll('a');
|
||||
const relAttrs = 'noreferrer noopener';
|
||||
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
const a = links[i];
|
||||
if (a.hostname != location.hostname) {
|
||||
if (a.hostname !== window.location.hostname) {
|
||||
a.rel = a.rel.length ? `${a.rel} ${relAttrs}` : relAttrs;
|
||||
a.target = '_blank';
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Based on fetching + caching in https://github.com/samikeijonen/11ty-wp ❤️
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
const flatcache = require('flat-cache');
|
||||
const path = require('path');
|
||||
const { DateTime } = require('luxon');
|
||||
|
||||
async function getNumPages(endPoint) {
|
||||
|
@ -14,6 +15,7 @@ async function fetchAll({ numPages, endPoint, type }) {
|
|||
const allPages = [];
|
||||
let allData = [];
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug(`Fetching ${type} content from wordpress via REST API`);
|
||||
|
||||
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
|
||||
|
@ -23,7 +25,7 @@ async function fetchAll({ numPages, endPoint, type }) {
|
|||
}
|
||||
|
||||
const results = await Promise.all(allPages);
|
||||
for (result of results) {
|
||||
for (const result of results) {
|
||||
let json = await result.json();
|
||||
|
||||
// Filter post data and only cache what we care about.
|
||||
|
@ -76,7 +78,8 @@ async function fetchAll({ numPages, endPoint, type }) {
|
|||
async function fetchData(type, endPoint) {
|
||||
const baseURL =
|
||||
process.env.WORDPRESS_BASE_URL || 'https://mozamo.wpengine.com';
|
||||
console.log(`WordPress base URL: ${baseURL}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.debug(`WordPress base URL: ${baseURL}`);
|
||||
|
||||
const url = `${baseURL}/${endPoint}`;
|
||||
|
||||
|
|
2459
yarn.lock
2459
yarn.lock
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче