On counting the areas covered by holes in a function in integration As far as I know, holes in a function at the endpoints of an interval aren't usually given any importance while integrating over that interval. For example, while calculating the area under the fractional part function from 0 to 1;

You don't really think of a hole as being an infinitesimally small width the area under which contributes to the calculated area(I'm not talking about the hole's area! I mean the area of the thin rectangle under it, when considering it as a small width). And I'm fine with that- it makes sense.
But there's this question that defines f(x) as 0 where x can be expressed as $\frac{n}{n+1}$, where n's an natural number, and as 1 everywhere else. And you're supposed to find the integral of f(x) from 0 to 2. So you've got a line, y=1, with dots on it that grow closer and more numerous as you get closer to 2, nearing an infinite  number.
Now the solution to the question just integrates the function from 0 to $\frac{1}{2}$, $\frac{1}{2}$ to $\frac{2}{3}$, $\frac{2}{3}$ to $\frac{3}{4}$ and so on until 1 and then a normal integral from 1 to 2-essentially just integrating y=1 from 0 to 2.
This seems odd. Isn't 'infinitesimally small quantities summed in infinite numbers forming actual numbers', the general idea of integration? Since there're an infinite number of small widths here, shouldn't they be considered as constituting some area and thereby affecting the calculation?
 A: Let's study this integral from a first principles approach, using directly the definition of Riemann integration. For concreteness, we make this definition explicit as well.
Riemann integration
Given an interval $[a, b]$, we define a partition $P$ of $[a, b]$ to be a sequence $x_0, x_1, \ldots, x_n,$ where $x_0 = a$ and $x_n = b$, and where $x_0 < x_1 < x_2 < \cdots < x_n$. We might refer to the partition $P$ as the sequence $P = \{x_i\}_{0 \leq i \leq n}$.
Another partition $Q = \{ y_j \}_{0 \leq j \leq m}$ of $[a, b]$ is said to be a refinement of $P$ if $x_i \in \{ y_j \}_{0 \leq j \leq m}$ for all $i$. Stated differently, if every sequence element of $P$ is also a sequence element of $Q$.
A Riemann sum of a function $f(x)$ on an interval $[a, b]$ with respect to a partition $P = \{ x_i \}_{0 \leq i \leq n}$ of $[a, b]$ is a sum of the form
$$ \sum_{i = 1}^n f(\xi_i)(x_i - x_{i-1}),$$
where $\xi_i \in [x_{i-1}, x_i]$. This is an estimate of the area under $f$ by a sum of rectangles, each of width $(x_i - x_{i-1})$ and of height $f(\xi_i)$, where $\xi_i$ is in the interval $[x_{i-1}, x_i]$.
Roughly, we say a function is Riemann integrable on $[a, b]$ if "for sufficiently fine partitions, all Riemann sums take essentially the same value $S$." More formally, we will say that $f$ is Riemann integrable on $[a, b]$ to a value $S$ if for any $\epsilon > 0$, there exists a partition $Q = \{y_j\}_{0 \leq j \leq n}$ such that for any refinement $P = \{ x_i \}_{0 \leq i \leq n}$ of $Q$, we have that
$$ \left \lvert \sum_{i = 1}^n f(\xi_i) (x_i - x_{i-1}) - S \right \rvert < \epsilon. \tag{1}$$
This problem
Consider the function
$$ f(x) = \begin{cases}
0 & x = \frac{n}{n+1} \;\; (n \in \mathbb{N}), \\
1 & \text{else},
\end{cases}$$
on the interval $[0, 2]$. We claim that $f$ is Riemann integrable, and that $\int_0^2 f(x) dx = 2$. Let's now prove this.
Choose any $\epsilon > 0$. Without loss of generality, we'll assume that $\epsilon < 1$. We will now choose a partition such that any refinement has Riemann sums within $\epsilon$ of $2$, as per the definition $(1)$.
We note that the Riemann sums for this function are trivially bounded above by $2$, as $f(x) \leq 1$ and the length of the interval is $2$. We will now examine lower bounds for Riemann sums. That is, from now on we seek a good lower bound for the Riemann sum. If we can show that the lower bound is within $\epsilon$ of $2$, we're done.
The idea behind our partition will be to include tiny intervals around each "exceptional" point $x = n/(n+1)$ so that those deviations don't matter very much. Specifically, for each point $x = n/(n+1)$, we associate the two points $x_{2n-1} = \frac{n}{n+1} - \frac{\epsilon}{4^n}$ and $x_{2n} = \frac{n}{n+1} + \frac{\epsilon}{4^n}$. We let $P_n$ denote the partition including the first $n$ pairs of this form, as well as the first point $x_0 = 0$ and final points $x_{2n+1} = 1$ and $x_{2n + 2} = 2$.
Thus, for example,
$$ P_1 = \left \{ 0, \frac{1}{2} - \frac{\epsilon}{4}, \frac{1}{2} + \frac{\epsilon}{4}, 1, 2 \right \}$$
and
$$ P_2 = \left \{ 0, \frac{1}{2} - \frac{\epsilon}{4}, \frac{1}{2} + \frac{\epsilon}{4}, \frac{2}{3} - \frac{\epsilon}{16}, \frac{2}{3} + \frac{\epsilon}{16}, 1, 2 \right \}.$$
Choose $N$ such that $\frac{1}{N+1} < \epsilon / 3$. Then we will use the partition $P_N$.
There are two sorts of intervals in the Riemann sum. There are intervals containing a point $\frac{n}{n+1}$, which are of the form $\frac{n}{n+1} \pm \frac{\epsilon}{4^n}$, and there are the intervals that don't contain a point $\frac{n}{n+1}$. In Riemann sums, the value of the terms on intervals not containing a point $\frac{n}{n+1}$ is $1$ times the length of the interval (as $f(x) = 1$ there). To minimize the Riemann sum, we will choose $\xi = \frac{n}{n+1}$ on each of those intervals, so that $f(\xi) = 0$, and ultimately these intervals don't contribute to the sum at all.
Notice that this is equivalent to adding up the lengths of the intervals not containing a point of the form $\frac{n}{n+1}$ with $n \leq N$. It happens to be easier to actually compute $2$ minus the sum of the lengths of the intervals that do contain a point of the form $\frac{n}{n+1}$.
(An upper bound for) the total length of the intervals containing a point of the form $\frac{n}{n+1}$ with $n \leq N$ is
$$
\sum_{n = 1}^N 2 \frac{\epsilon}{4^n} + \left[1 - \frac{N}{N+1}\right]
\leq \frac{2}{3} \epsilon + \frac{1}{3} \epsilon = \epsilon.
$$
The sum on the left is a sum over each interval $[x_{2n-1}, x_{2n}]$, i.e. those intervals of the form $[\frac{n}{n+1} - \frac{\epsilon}{4^n}, \frac{n}{n+1} + \frac{\epsilon}{4^n}]$, and the remaining term is (a slight overestimate for) the final interval $[x_{2N}, x_{2N+1}] = [\frac{N}{N+1} + \frac{\epsilon}{4^N}, 1]$. The length of the final interval is (a bit less than) $\frac{1}{N+1}$, which is less than $\epsilon / 3$ (as that's exactly how we chose $N$).
This shows that the intervals on which terms in the Riemann sum can take the value $0$ have total length at most $\epsilon$, and thus the remaining intervals have total length at least $2 - \epsilon$.
Thus any refinement of $P_N$ will have Riemann sums bounded above by $2$ and bounded below by $2 - \epsilon$. This shows that $f$ is integrable, and that it integrates to $2$.
General takeaway
In this explicit solution, there are lots of details (as explicit calculations with integrals are always detail-full and messy). But the key was that we could discount the points of discontinuity by putting a sequence of $\epsilon$-intervals around each point in a way that they don't matter. Since there are countably many points of discontinuity, we can enumerate these "exceptional" intervals and make them small enough to not contribute.
A: First, is $f$ even Riemann integrable? Yes. It is bounded and it is discontinuous on a set with measure zero, i.e., the set $S=\{n/(n+1)\in\mathbb{Q}:n\in\mathbb{N}\}$. This set has measure zero since it is countable. This is the Lebesgue integrability criterion for Riemann integrability. A quick google search will give more detail on this.
Second, your concern is definitely a valid one. The solution you described really only works because there aren't enough points of discontinuity of your function $f$ on $[0,1]$ for it to effect integrability nor the value of the integral of $f$. I am not experienced enough in measure theory to describe the nuts-and-bolts of all of this to you, however, as some more examples similar to this one, consider Dirichlet's function(s) or Thomae's function. As another note, uniform convergence and pointwise convergence address similar issues.
Define the sequence $a_k=k/(k+1)$. Being only slightly less hand-wavy than the solution you described, we essentially have
$$\int_0^1f(x)dx=\lim_{n\to\infty}\sum_{k=0}^{n} \int_{a_k}^{a_{k+1}}1\,dx=\lim_{n\to\infty}\sum_{k=0}^{n}(a_{k+1}-a_k)$$
where we break up the integral at points of discontinuity since they contribute no area to the integral (the deeper reason behind this is again, measure theory; the tag-line for this would be that the integral of any measureable function over a set of measure zero is zero).
Note that we definitely cannot interchange the summation and integration sign in this case; it wouldn't even make sense here
(see Fubini/Tonelli's Theorem, the dominated convergence theorem, the monotone convergence theorem, and this Quora answer for more on when you can interchange limits).
After noting that $$a_{k+1}-a_k=\frac{k+1}{k+2}-\frac{k}{k+1}$$
and eventually seeing a pattern with the partial sums, we find that $$\sum_{k=0}^{n}(a_{k+1}-a_k)=1-\frac{1}{n+2} $$ which clearly converges to $1$ as $n\to\infty$.
